Irjet V6i162 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 06 Issue: 01 | Jan 2019 www.irjet.net p-ISSN: 2395-0072

Pattern Programs in Java


Mrs. Kanchanmala D Talekar1, Mr. Mithun Jadhav2, Mr. Ashok Kakad3
1Lecturer, Dept. of Computer Engineering, GVAP Shelu, Maharashtra, India.
2 HOD, Dept. of Computer Engineering, GVAP Shelu, Maharashtra, India.
3Lecturer, Dept. of Computer Engineering, GVAP Shelu, Maharashtra, India.

---------------------------------------------------------------------***----------------------------------------------------------------------
Display Patterns in java Program 3:

Program 1: class Pattern3{


public static void main(String args[]){
class Pattern1{ for(int i=5;i>=1;i--){
public static void main(String args[]){ for(int j=1;j<=i;j++){
for(int i=1;i<=5;i++){ System.out.print(i);
for(int j=1;j<=i;j++){ }
System.out.print("* "); System.out.println();
} }
System.out.println(); }
} }
}
} Output:

Output

Program 4:
Program 2:
class Pattern4{
class Pattern2{ public static void main(String args[]){
public static void main(String args[]){ for(int i=5;i>=1;i--){
for(int i=1;i<=5;i++){ for(int j=1;j<=i;j++){
for(int j=1;j<=i;j++){ System.out.print("* ");
System.out.print(i); }
} System.out.println();
System.out.println(); }
} }
} }
} Output:

Output:

© 2019, IRJET | Impact Factor value: 7.211 | ISO 9001:2008 Certified Journal | Page 345
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 06 Issue: 01 | Jan 2019 www.irjet.net p-ISSN: 2395-0072

Program 5: Program 7:

class Pattern5{ class Pattern7{


public static void main(String args[]){ public static void main(String args[]){
int sp=20; int sp=20;
for(int i=1;i<=5;i++){ int i,j,k;
for(int k=1;k<=sp;k++){ for( i=1;i<=5;i++){
System.out.print(" "); for( k=1;k<=sp;k++){
} System.out.print(" ");
sp--; }
for(int j=1;j<=i;j++){ sp--;
System.out.print("* "); for( j=1;j<=i;j++){
} System.out.print("* ");
System.out.println(); }
} System.out.println();
} }
} sp=20;
for(i=4;i>=1;i--){
Output: for(k=4;k<=sp;k++){
System.out.print(" ");
}
sp++;
for(j=1;j<=i;j++){
System.out.print("* ");
}
System.out.println();
}
}
Program 6: }

class Pattern6{ Output:


public static void main(String args[]){
int sp=20;
for(int i=5;i>=1;i--){
for(int k=5;k<=sp;k++){
System.out.print(" ");
}
sp++;
for(int j=1;j<=i;j++){
System.out.print("* ");
}
System.out.println();
} Program 8:
}
} class Pattern8{
public static void main(String args[]){
Output: int n, c, k, space, count = 1;
space =n=5;
for (c = 1; c <= n; c++){
for (k = 1; k < space; k++)
System.out.print(" ");
for (k = 1; k <= c; k++){
System.out.print("*");
if (c > 1 && count < c){
System.out.print("A");
count++;
© 2019, IRJET | Impact Factor value: 7.211 | ISO 9001:2008 Certified Journal | Page 346
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 06 Issue: 01 | Jan 2019 www.irjet.net p-ISSN: 2395-0072

} else
} c = c*(i-j+1)/j;
System.out.print("\n"); System.out.print(" "+c);
space--; System.out.print("\n");
count = 1; }
} }
} }
}
Output:
Output:

Program 9: Program 11:

class Pattern9{ class Pattern11{


public static void main(String args[]){ public static void main(String args[]){
int rows, i, j, number= 1; int i, space, rows, k=0, count = 0, count1 = 0;
rows=4; rows=5;
for(i=1; i <= rows; i++){ for(i=1; i<=rows; ++i) {
for(j=1; j <= i; ++j){ for(space=1; space <= rows-i; ++space) {
System.out.print(number); System.out.print(" ")
++number; ++count;
} }
System.out.print("\n"); while(k != 2*i-1) {
} if (count <= rows-1) {
} System.out.print(" "+(i+k));
} ++count;
}
Output: else{
++count1;
System.out.print(" "+(i+k-2*count1));
}
++k;
}
count1 = count = k = 0;
System.out.print("\n");
}
}
}
Program 10:
Output:
class Pattern10{
public static void main(String args[]){
int rows, c = 1, space, i, j;rows=5;
for(i=0; i<rows; i++){
for(space=1; space <= rows-i; space++)
System.out.print(" ")
if (j==0 || i==0)
c = 1;

© 2019, IRJET | Impact Factor value: 7.211 | ISO 9001:2008 Certified Journal | Page 347
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 06 Issue: 01 | Jan 2019 www.irjet.net p-ISSN: 2395-0072

Program 12: System.out.print("*");


}
class Pattern12{ sp = sp + 1;
public static void main(String args[]){ System.out.print("\n");
for(int i=1;i<=5;i++){ }
for(int j=1;j<=5;j++){ }
System.out.print("* "); }
}
System.out.println(); Output:
}
}
}

Output:

Program 15:
class Pattern15{
Program 13: public static void main(String args[]) {
class Pattern13{ int i,j,k,sp=1;
public static void main(String args[]){ for (i=1; i<=5; i++) {
for (int i=1; i<=5; i++) { for (k=sp; k<=5; k++) {
for (int j=5; j>=i; j--) { System.out.print(" ");
System.out.print(" "); }
} for (j=0; j< i; j++) {
for (int k=1; k<=i; k++) { System.out.print("*");
System.out.print("*"); }
} sp = sp + 1;
System.out.print("\n"); System.out.print("\n");
} }
} sp = 1;
} for (i=4; i>=1; i--) {
Output: for (k=sp; k>=0; k--) {
System.out.print(" ");
}
for (j=i; j>=1; j--) {
System.out.print("*");
}
sp = sp + 1;
System.out.print("\n");
}
}
}
Program 14: Output:
class Pattern14{
public static void main(String args[]) {
int i,j,k,sp=1;
for (i=5; i>=1; i--) {
for (k=sp; k>=0; k--) {
System.out.print(" ");// only 1 space
}
for (j=i; j>=1; j--) {

© 2019, IRJET | Impact Factor value: 7.211 | ISO 9001:2008 Certified Journal | Page 348
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 06 Issue: 01 | Jan 2019 www.irjet.net p-ISSN: 2395-0072

Program 16: Program 18:


class Pattern16{ class Pattern18{
public static void main(String args[]) { public static void main(String args[]) {
int i, j=5, k, x; int i,j,k;
for (i=1;i<=5;i++) { for (i=1;i<=5;i++) {
for (k=1;k<=j;k++) { for (j=1;j<=5;j++) {
System.out.print(" "); if(j<=i)
} System.out.print(j);
for (x=1;x<=i;x++) { else
System.out.print(i); System.out.print(" ");
System.out.print(" "); }
} for (j=5;j>=1;j--) {
System.out.print("\n"); if(j<=i)
j=j-1; System.out.print(j);
} else
} System.out.print(" ");
} }
System.out.print("\n");
Output:
}
}
}
Output:

Program 17:
class Pattern17{
public static void main(String args[]) {
int i,j,k;
for (i=1;i<=5;i++) { Program 19:
for (j=5;j>=1;j--) { class Pattern19{
if(j<=i) public static void main(String args[]) {
System.out.print(j); int i,j,k;
else for (i=1;i<=5;i++) {
System.out.print(" "); j=i;
} for (k=1;k<=i;k++) {
System.out.print("\n"); System.out.print(j++);
} }
} System.out.print("\n");
} }
Output: }
}
Output:

© 2019, IRJET | Impact Factor value: 7.211 | ISO 9001:2008 Certified Journal | Page 349
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 06 Issue: 01 | Jan 2019 www.irjet.net p-ISSN: 2395-0072

Program 20: for (j=i;j<5;j++) {


System.out.print(" ");
class Pattern20{
}
public static void main(String args[]) {
for (k=1;k<(i*2);k++) {
int i,j;
System.out.print(k);
for (i=1;i<=4;i++) {
}
for (j=i;j>1;j--)
System.out.print("\n");
System.out.print(j);
}
for (j=1;j<=i;j++)
for (i=4;i>=1;i--) {
System.out.print(j);
for (j=5;j>i;j--) {
System.out.print("\n");
System.out.print(" ");
}
}
}
for (k=1;k<(i*2);k++) {
}
System.out.print(k);
Output: }
System.out.print("\n");
}
}
}
Output:

Program 21:
class Pattern21{
public static void main(String args[]) {
int i,j;
for (i=1;i<=5;i++) {
for (j=1;j<=5;j++) { Program 23:
if(j==5 || j==1 || i==1 || i==5)
System.out.print("1"); class Pattern23{
else public static void main(String args[]) {
System.out.print(" "); int i,j;
} for (i=1;i<=10;i++) {
System.out.print("\n"); for (j=1;j<=i;j++) {
} System.out.print(i*j);
} }
} System.out.print("\n");
}
Output: }
}
Output:

Program 22:
class Pattern22{
public static void main(String args[]) {
int i, j, k;
for (i=1;i<=5;i++) {
© 2019, IRJET | Impact Factor value: 7.211 | ISO 9001:2008 Certified Journal | Page 350
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 06 Issue: 01 | Jan 2019 www.irjet.net p-ISSN: 2395-0072

Program 24: Output:

class Pattern24{
public static void main(String args[]) {
int i,j,r,k=1;
r=10;
System.out.print("FLOYD'S TRIANGLE\n\n");
for(i=1;i<=r;i++){
for(j=1;j<=i;j++,k++)
System.out.print(k);
System.out.print("\n");
}
} REFERENCES
}
1. http://scanftree.com/programs/c/programs-
Output: to-print-pyramid-patterns-in-c-part-1/

Program 25:
class Pattern25{
public static void main(String args[]) {
int i, j, rows;
/* Input number of rows from user */
rows=8;
for(i=1; i<=rows; i++) {
/* Print trailing spaces */
for(j=1; j<=rows-i; j++) {
System.out.print(" ");
}
/* Print stars and center spaces */
for(j=1; j<=rows; j++) {
if(i==1 || i==rows || j==1 || j==rows)
System.out.print("*");
else
System.out.print(" ");
}
System.out.print("\n");
}
}
}

© 2019, IRJET | Impact Factor value: 7.211 | ISO 9001:2008 Certified Journal | Page 351

You might also like