Pattern Programs In Java Using Numbers In Essays


Number Pattern Programs In Java :

Java programs to print the numbers or any other symbols in different patterns are one of the frequently asked interview programs mostly for freshers. Because, they test the candidate’s logical ability as well as coding skills which are ‘must have skills’ for any software engineer. In this post, I have collected some of the different number pattern programs in java and have tried to solve them. I hope they will be helpful for you guys.

Pattern 1 :

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j+" "); } System.out.println(); } //Close the resources sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7

Pattern 2 :

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(i+" "); } System.out.println(); } //Close the resources sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7

Pattern 3 :

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); //Printing upper half of the pattern for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j+" "); } System.out.println(); } //Printing lower half of the pattern for (int i = rows-1; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j+" "); } System.out.println(); } //Closing the resources sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Pattern 4 :

1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = rows; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j+" "); } System.out.println(); } //Closing the resources sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Pattern 5 :

7 6 5 4 3 2 1
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = 1; i <= rows; i++) { for (int j = rows; j >= i; j--) { System.out.print(j+" "); } System.out.println(); } //Closing the resources sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
7 6 5 4 3 2 1
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7

Pattern 6 :

7
7 6
7 6 5
7 6 5 4
7 6 5 4 3
7 6 5 4 3 2
7 6 5 4 3 2 1

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = rows; i >= 1; i--) { for (int j = rows; j >= i; j--) { System.out.print(j+" "); } System.out.println(); } //Closing the resources sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
7
7 6
7 6 5
7 6 5 4
7 6 5 4 3
7 6 5 4 3 2
7 6 5 4 3 2 1

Pattern 7 :

7 6 5 4 3 2 1
6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = rows; i >= 1; i--) { for (int j = i; j >= 1; j--) { System.out.print(j+" "); } System.out.println(); } //Closing the resources sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
7 6 5 4 3 2 1
6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

Pattern 8 :

1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); //Printing upper half of the pattern for (int i = rows; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j+" "); } System.out.println(); } //Printing lower half of the pattern for (int i = 2; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j+" "); } System.out.println(); } //Closing the resources sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7

Pattern 9 :

1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = 1; i <= rows; i++) { //Printing first half of the row for (int j = 1; j <= i; j++) { System.out.print(j+" "); } //Printing second half of the row for (int j = i-1; j >= 1; j--) { System.out.print(j+" "); } System.out.println(); } //Closing the resources sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1

Pattern 10 :

1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
7 6 5 4 3 2 1

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = 1; i <= rows; i++) { for (int j = i; j >= 1; j--) { System.out.print(j+" "); } System.out.println(); } //Close the resources sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
7 6 5 4 3 2 1

Pattern 11 :

1234567 234567 34567 4567 567 67 7 67 567 4567 34567 234567 1234567

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("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++) { System.out.print(" "); } //Printing i to rows value at the end of each row for (int j = i; j <= rows; j++) { System.out.print(j); } System.out.println(); } //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++) { System.out.print(" "); } //Printing i to rows value at the end of each row for (int j = i; j <= rows; j++) { System.out.print(j); } System.out.println(); } //Closing the resources sc.close(); } }

Output :

How many rows you want in this pattern? 7 Here is your pattern....!!! 1234567 234567 34567 4567 567 67 7 67 567 4567 34567 234567 1234567

Pattern 12 :

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

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("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++) { System.out.print(" "); } //Printing i to rows value at the end of each row for (int j = i; j <= rows; j++) { System.out.print(j+" "); } System.out.println(); } //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++) { System.out.print(" "); } //Printing i to rows value at the end of each row for (int j = i; j <= rows; j++) { System.out.print(j+" "); } System.out.println(); } //Closing the resources sc.close(); } }

Output :

How many rows you want in this pattern? 7 Here is your pattern....!!! 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

Pattern 13 :

1
10
101
1010
10101
101010
1010101

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { if(j%2 == 0) { System.out.print(0); } else { System.out.print(1); } } System.out.println(); } sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
1
10
101
1010
10101
101010
1010101

Pattern 14 :

1010101
0101010
1010101
0101010
1010101
0101010
1010101

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("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++) { System.out.print(num); num = (num == 0)? 1 : 0; } } else { num = 1; for (int j = 1; j <= rows; j++) { System.out.print(num); num = (num == 0)? 1 : 0; } } System.out.println(); } sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
1010101
0101010
1010101
0101010
1010101
0101010
1010101

Pattern 15 :

1111111
1111122
1111333
1114444
1155555
1666666
7777777

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= rows-i; j++) { System.out.print(1); } for (int j = 1; j <= i; j++) { System.out.print(i); } System.out.println(); } sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
1111111
1111122
1111333
1114444
1155555
1666666
7777777

Pattern 16 :

0000000
0100000
0020000
0003000
0000400
0000050
0000006

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = 0; i < rows; i++) { for (int j = 0; j < rows; j++) { if(i == j) { System.out.print(i); } else { System.out.print(0); } } System.out.println(); } sc.close(); } }

Output :

How many rows you want in this pattern?
7
Here is your pattern….!!!
0000000
0100000
0020000
0003000
0000400
0000050
0000006

Pattern 17 :

1
2 6
3 7 10
4 8 11 13
5 9 12 14 15

Java Program :

import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("How many rows you want in this pattern?"); int rows = sc.nextInt(); System.out.println("Here is your pattern....!!!"); for (int i = 1; i <= rows; i++) { int num = i; for (int j = 1; j <= i; j++) { System.out.print(num+" "); num = num+rows-j; } System.out.println(); } sc.close(); } }

Output :

How many rows you want in this pattern?
5
Here is your pattern….!!!
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15

Pattern 18 :

Different Pyramid Pattern Programs In Java

Pattern 19 :

Diamond Pattern Programs In Java

Pattern 20 :

Floyd’s Triangle In Java


Just released: 30 new live online trainings on O'Reilly's learning platform Get instructor-led training in Python React PMP security and more. We just opened up more than 30 new live online trainings for February March and April on our learning platform. These trainings give you hands-on experience in critical topics. You'll learn from instructors in OReillys network of expert practitioners and from our trusted partners. Space is limited and these trainings often fill up. Reactive…

Maven tutorial provides basic and advanced concepts of apache maven, Maven is a powerful project management tool that is based on project object Model.

JavaTpoint provides easy and point to point learning of various tutorials such as Java Tutorial, Core Java Tutorial, Android, Design Pattern, JavaScript, AJAX, SQL, Cloud Computing, Python etc. Javatpoint is growing day by day with lot of new contents on various software technologies. We provide tutorials, training, interview questions, forum, seo services etc.

0 thoughts on “Pattern Programs In Java Using Numbers In Essays

Leave a Reply

Your email address will not be published. Required fields are marked *