Geeksfastprogrammer

Logical Program

Java Pattern Program
Pattern:1-
/*

11111
11111
11111
11111
11111

*/


class A 
{
public static void main(String[] args) 
{
for(int rows = 1; rows <= 5; rows++)
{
for(int cols = 1; cols <= 5; cols++)
{
System.out.print(1);
}
System.out.println();
}
}
}

Pattern:2-
/*

000000
000000
000000
000000

*/

class M2 
{
public static void main(String[] args) 
{
for(int rows = 1; rows <= 4; rows++)
{
for(int cols = 1; cols <= 6; cols++)
{
System.out.print(0);
}
System.out.println();
}
}
}

Pattern:3-
/*

****
****
****
****
****
****

*/


class M3 
{
public static void main(String[] args) 
{
for(int rows = 1; rows <= 6; rows++)
{
for(int cols =  1; cols <= 4; cols++)
{
System.out.print("*");
}
System.out.println();
}
}
}

Pattern:4-
/*

1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1

*/


class  M4
{
public static void main(String[] args) 
{
for(int rows = 1; rows <= 4; rows++)
{
for(int cols = 1; cols <= 8; cols++)
{
System.out.print("1 ");
//System.out.print(" ");
}
            System.out.println();
}
}
}

Pattern:5-
/*

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

*/



class  M5
{
public static void main(String[] args) 
{
for(int rows = 1; rows <= 8; rows++)
{
for(int cols = 1; cols <=4; cols++)
{
System.out.print("0 ");

}
System.out.println();
}
}
}

Pattern:6-
/*

123456
123456
123456
123456
123456
123456

*/

class  M6
{
public static void main(String[] args) 
{
for(int rows = 1; rows <=6; rows++)
{
for(int cols = 1; cols <= 6; cols++)
{
System.out.print(cols);
}
System.out.println();
}
}
}
Pattern:7-
/*

456789
456789
456789
456789
456789
456789
456789
456789


*/

class M7 
{
public static void main(String[] args) 
{
for(int rows = 1; rows <= 8; rows++)
{
for(int cols  = 4; cols <= 9; cols++)
{
System.out.print(cols);
}
System.out.println();
}
}
}

Pattern:8-
/*

987654321
987654321
987654321
987654321
987654321
987654321
987654321
987654321

*/



class  M8
{
public static void main(String[] args) 
{
for(int rows = 1; rows <= 8; rows++)
{
for(int cols = 9; cols >=1; cols--)
{
System.out.print(cols);
}
System.out.println();
}
}
}


Pattern:9-
/*

1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5

*/


class M9 
{
public static void main(String[] args) 
{
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= 8; j++)
{
System.out.print(i + " ");
}
System.out.println();
}
}
}


Pattern:10-
/*
 9 8 7 6 5 
 8 7 6 5 4
 7 6 5 4 3
 6 5 4 3 2
 5 4 3 2 1

 */



class M10 
{
public static void main(String[] args) 
{
for(int i = 9; i >= 5; i--)
{
for(int j = i; j >= (i - 4); j--)
{
System.out.print(j + " ");
}
System.out.println();
}
}
}

Pattern:11-
/*

12345
23456
34567
45678
56789

*/



class M11 
{
public static void main(String[] args) 
{
for(int i = 1; i <= 5; i++)
{
for(int j = i; j <=(i + 4); j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
Pattern:12-
/*

12345
1234
123
12
1

*/

class  M12
{
public static void main(String[] args) 
{
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j <= (6 - i); j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
Pattern:13-
/*

1
12
123
1234
12345

*/
class  M13
{
public static void main(String[] args) 
{
for(int i = 1; i <= 5; i++)
{
for(int j = 1; j < (1 + i); j++)
{
System.out.print(j);
}
System.out.println();
}
}
}

Pattern:14-
/*
1
 2
  3
   4
    5

*/


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

Pattern:15-
/*

12345
678910
1112131415


*/
class M15 
{
public static void main(String[] args) 
{
for(int i = 1; i <= 3; i++)
{
for(int j = 1; j <= 15; j++)
{
System.out.print(j);
if(j == 5)
{
System.out.println();
}
if(j == 10)
{
System.out.println();
}
if(j == 15)
{
return;
}
}
System.out.println();
}
}
}

Pattern:16-
/*

12345678
87654321
12345678
87654321

*/



class M16 
{
public static void main(String[] args) 
{
for(int i = 1; i <= 4; i++)
{
if(i == 3)
{
return;
}
for(int j = 1; j <= 8; j++)
{
System.out.print(j);
}
System.out.println();
for(int j = 8; j >= 1; j--)
{
System.out.print(j);
}
System.out.println();
}
}
}

Pattern:17-
/*

1
11
111
1111
11111
111111
1111111
11111111

*/

class M17 
{
public static void main(String[] args) 
{
int rows = 8;
for(int i = 1; i <= rows; i++)
{
for(int j = 1; j <= i; j++)
{
System.out.print(1);
}
System.out.println();
}
}
}

Pattern:18-
/*

1
22
333
4444
55555
666666
7777777
88888888

*/

class M18 
{
public static void main(String[] args) 
{
int rows = 8;
for(int i = 1; i <= rows; i++)
{
for(int j = 1; j <=i; j++)
{
System.out.print(i);
}
System.out.println();
}
}
}

Pattern:19-
/*

1
12
123
1234
12345
123456
1234567
12345678

*/


class  M19
{
public static void main(String[] args) 
{
int rows = 8;
for(int i = 1; i <= rows; i++)
{
for(int j = 1; j <=i; j++)
{
System.out.print(j);
}
System.out.println();
}
}
}

Pattern:20-
/*

11111111
2222222
333333
44444
5555
666
77
8

*/

class M20 
{
public static void main(String[] args) 
{
int rows = 8;
for(int i = 1; i <= rows; i++)
{
for(int j = 1; j<= (rows + 1 - i); j++)
{
System.out.print(i);
}
System.out.println();
}
}
}

Pattern:21-
/*

12345678
1234567
123456
12345
1234
123
12
1

*/

class M21 
{
public static void main(String[] args) 
{
int rows = 8;
for(int i = 1; i <= rows; i++)
{
for(int j = 1; j <= (rows + 1 - i); j++)
{
System.out.print(j);
}
System.out.println();
}
}
}

Pattern:22-
/*

12345
   6
  7
 8
9

*/


class M22
{
public static void main(String[] args) 
{
for(int i = 1; i<= 5;i++)
{
System.out.print(i);
}
System.out.println();
for(int j = 6; j <=9; j++)
{
for(int space = 1; space <=(9 - j); space++)
{
System.out.print(" ");
}
System.out.println(j);
}
}
}

Pattern:23-
/*

12345
   6
  7
 8
910111213

*/

class  M31
{
public static void main(String[] args) 
{
for(int i = 1; i <=5; i++)
{
System.out.print(i);
}
System.out.println();
for(int j = 6; j <=8; j++)
{
for(int space = 1; space <=(9 - j); space++)
{
System.out.print(" ");
}
System.out.println(j);
}
for(int k = 9; k <=13; k++)
{
System.out.print(k);
}
}
}


Previous
Next Post »
New comments are not allowed.