19 Different Number Pattern Programs In Java
Java programs to print the numbers or any different pattern is one of the easiest
ways to kick off your coding skills in java. In this post I have taken some different
number pattern programs in java and tried to solve them . Please add more pattern
and their code in the comment sections.
Pattern programs in java : Pattern 1
1
12
123
1234
12345
123456
1234567
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
[Link](j+" ");
}
[Link]();
}
//Close the resources
[Link]();
}
}
Pattern programs in java : Pattern 2
1
12
123
1234
12345
1234567
123456
12345
1234
123
12
1
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
//Printing upper half of the pattern
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
[Link](j+" ");
}
[Link]();
}
//Printing lower half of the pattern
for (int i = rows-1; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
[Link](j+" ");
}
[Link]();
}
//Closing the resources
[Link]();
}
}
Pattern programs in java : Pattern 3
1
22
333
4444
55555
666666
7777777
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
[Link](i+" ");
}
[Link]();
}
//Close the resources
[Link]();
}
}
Pattern programs in java : Pattern 4
7654321
765432
76543
7654
765
76
7
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = rows; j >= i; j--)
{
[Link](j+" ");
}
[Link]();
}
//Closing the resources
[Link]();
}
}
Pattern programs in java : Pattern 5
1234567
123456
12345
1234
123
12
1
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = rows; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
[Link](j+" ");
}
[Link]();
}
//Closing the resources
[Link]();
}
}
Pattern programs in java : Pattern 6
7654321
654321
54321
4321
321
21
1
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = rows; i >= 1; i--)
{
for (int j = i; j >= 1; j--)
{
[Link](j+" ");
}
[Link]();
}
//Closing the resources
[Link]();
}
}
Pattern programs in java : Pattern 7
7
76
765
7654
76543
765432
7654321
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = rows; i >= 1; i--)
{
for (int j = rows; j >= i; j--)
{
[Link](j+" ");
}
[Link]();
}
//Closing the resources
[Link]();
}
}
Pattern programs in java : Pattern 8
1
121
12321
1234321
123454321
12345654321
1234567654321
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
//Printing first half of the row
for (int j = 1; j <= i; j++)
{
[Link](j+" ");
}
//Printing second half of the row
for (int j = i-1; j >= 1; j--)
{
[Link](j+" ");
}
[Link]();
}
//Closing the resources
[Link]();
}
}
Pattern programs in java : Pattern 9
1234567
123456
12345
1234
123
12
1
12
123
1234
12345
123456
1234567
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
//Printing upper half of the pattern
for (int i = rows; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
[Link](j+" ");
}
[Link]();
}
//Printing lower half of the pattern
for (int i = 2; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
[Link](j+" ");
}
[Link]();
}
//Closing the resources
[Link]();
}
}
Pattern programs in java : Pattern 10
1234567
234567
34567
4567
567
67
7
67
567
4567
34567
234567
1234567
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
//Printing upper half of the pattern
for (int i = 1; i <= rows; i++)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j < i; j++)
{
[Link](" ");
}
//Printing i to rows value at the end of each row
for (int j = i; j <= rows; j++)
{
[Link](j);
}
[Link]();
}
//Printing lower half of the pattern
for (int i = rows-1; i >= 1; i--)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j < i; j++)
{
[Link](" ");
}
//Printing i to rows value at the end of each row
for (int j = i; j <= rows; j++)
{
[Link](j);
}
[Link]();
}
//Closing the resources
[Link]();
}
}
Pattern programs in java : Pattern 11
1
21
321
4321
54321
654321
7654321
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = i; j >= 1; j--)
{
[Link](j+" ");
}
[Link]();
}
//Close the resources
[Link]();
}
}
Pattern programs in java : Pattern 12
1
10
101
1010
10101
101010
1010101
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
if(j%2 == 0)
{
[Link](0);
}
else
{
[Link](1);
}
}
[Link]();
}
[Link]();
}
}
Pattern programs in java : Pattern 13
1 2 3 4 5 6 7
2 3 4 5 6 7
3 4 5 6 7
4 5 6 7
5 6 7
6 7
7
6 7
5 6 7
4 5 6 7
3 4 5 6 7
2 3 4 5 6 7
1 2 3 4 5 6 7
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
//Taking rows value from the user
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
//Printing upper half of the pattern
for (int i = 1; i <= rows; i++)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j < i; j++)
{
[Link](" ");
}
//Printing i to rows value at the end of each row
for (int j = i; j <= rows; j++)
{
[Link](j+" ");
}
[Link]();
}
//Printing lower half of the pattern
for (int i = rows-1; i >= 1; i--)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j < i; j++)
{
[Link](" ");
}
//Printing i to rows value at the end of each row
for (int j = i; j <= rows; j++)
{
[Link](j+" ");
}
[Link]();
}
//Closing the resources
[Link]();
}
}
Pattern programs in java : Pattern 14
1111111
1111122
1111333
1114444
1155555
1666666
7777777
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= rows-i; j++)
{
[Link](1);
}
for (int j = 1; j <= i; j++)
{
[Link](i);
}
[Link]();
}
[Link]();
}
}
Pattern programs in java : Pattern 15
1010101
0101010
1010101
0101010
1010101
0101010
1010101
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
int num;
if(i%2 == 0)
{
num = 0;
for (int j = 1; j <= rows; j++)
{
[Link](num);
num = (num == 0)? 1 : 0;
}
}
else
{
num = 1;
for (int j = 1; j <= rows; j++)
{
[Link](num);
num = (num == 0)? 1 : 0;
}
}
[Link]();
}
[Link]();
}
}
Pattern programs in java : Pattern 16
1
26
3 7 10
4 8 11 13
5 9 12 14 15
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
int num = i;
for (int j = 1; j <= i; j++)
{
[Link](num+" ");
num = num+rows-j;
}
[Link]();
}
[Link]();
}
}
Pattern programs in java : Pattern 17
1234567
2345671
3456712
4567123
5671234
6712345
7123456
import [Link];
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner([Link]);
[Link]("How many rows you want in this pattern?");
int rows = [Link]();
[Link]("Here is your pattern....!!!");
for(int i=1;i< rows+1 ;i++)
{
for(int j=i; j < rows+1 ;j++)
{
[Link](j + " ");
}
for(int k=1; k < i ;k++)
{
[Link](k + " ");
}
[Link]();
}
[Link]();
}
}
Pattern programs in java : Pattern 18
1
23
456
7 8 9 10
11 12 13 14 15
import [Link];
public class MainClass
{
public static void main(String[] args)
{
[Link]("How many rows you want in this pattern?");
Scanner sc = new Scanner([Link]);
int noOfRows = [Link]();
int value = 1;
[Link]("Here is your pattern :");
for (int i = 1; i <= noOfRows; i++)
{
for (int j = 1; j <= i; j++)
{
[Link](value+"\t");
value++;
}
[Link]();
}
}
}
Pattern programs in java : Pattern 19
1
22
333
4444
55555
666666
7777777
import [Link];
public class MainClass
{
public static void main(String[] args)
{
[Link]("How many rows you want in this pattern");
Scanner sc = new Scanner([Link]);
int noOfRows = [Link]();
for (int i = 1; i <= noOfRows; i++)
{
for (int j = 1; j <= i; j++)
{
[Link](i+" ");
}
[Link]();
}
}
}