In this article, we will learn to print the different Number pattern programs in Java. This is one of the important Java interview questions for fresher. Let’s look into the below possible number pattern programs
Number Pattern Programs In Java
Pattern 1:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern1 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
Pattern 2:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern2 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(i + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Pattern 3:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern3 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } for (int i = rows; i >= 1; i--) { for (int j = 1; j < i; j++) { System.out.print(j + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Pattern 4:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern4 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = rows; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
Pattern 5:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern5 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = rows; i >= 1; i--) { for (int j = i; j >= 1; j--) { System.out.print(j + " "); } System.out.println(); } for (int i = 1; i <= rows; i++) { for (int j = i; j >= 1; j--) { System.out.print(j + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1
Pattern 6:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern6 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= i; k++) { System.out.print(k + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
Pattern 7:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern7 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = rows; j >= i; j--) { System.out.print(j + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 5 4 3 2 1 5 4 3 2 5 4 3 5 4 5
Pattern 8:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern8 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = rows; i >= 1; i--) { for (int j = rows; j >= i; j--) { System.out.print(j + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 5 5 4 5 4 3 5 4 3 2 5 4 3 2 1
Pattern 9:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern9 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = rows; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Pattern 10:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern10 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); int k = 1; System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(k + " "); k++; } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Pattern 11:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern11 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = i; j >= 1; j--) { System.out.print(j + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1
Pattern 12:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern12 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { int temp = i; for (int j = i; j >= 1; j--) { System.out.print(temp + " "); temp = temp + rows; } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 7 3 8 13 4 9 14 19 5 10 15 20 25
Pattern 13:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern13 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(" "); } int temp = 1; for (int k = 1; k <= i; k++) { System.out.print(temp + " "); temp = temp * (i - k) / (k); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Pattern 14:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern14 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } for (int k = i - 1; k >= 1; k--) { System.out.print(k + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the 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
Pattern 15:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern15 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j < i; j++) { System.out.print(" "); } for (int k = 1; k <= rows - i + 1; k++) { System.out.print(k + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Pattern 16:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern16 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= i; k++) { System.out.print(k + " "); } System.out.println(); } for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(" "); } for (int k = 1; k <= rows - i; k++) { System.out.print(k + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Pattern 17:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern17 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j < i; j++) { System.out.print(" "); } for (int k = i; k <= rows; k++) { System.out.print(k); } System.out.println(); } for (int i = rows; i >= 1; i--) { for (int j = 1; j < i; j++) { System.out.print(" "); } for (int k = i; k <= rows; k++) { System.out.print(k); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 12345 2345 345 45 5 5 45 345 2345 12345
Pattern 18:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern18 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j < i; j++) { System.out.print(" "); } for (int k = i; k <= rows; k++) { System.out.print(k + " "); } System.out.println(); } for (int i = rows; i >= 1; i--) { for (int j = 1; j < i; j++) { System.out.print(" "); } for (int k = i; k <= rows; k++) { System.out.print(k + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 4 5 2 3 4 5 3 4 5 4 5 5 5 4 5 3 4 5 2 3 4 5 1 2 3 4 5
Pattern 19:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern19 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = rows; i >= 1; i--) { for (int j = 1; j < i; j++) { System.out.print(" "); } for (int k = i; k <= rows; k++) { System.out.print(k + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 5 4 5 3 4 5 2 3 4 5 1 2 3 4 5
Pattern 20:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern20 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= i; k++) { System.out.print(k); } for (int l = i - 1; l >= 1; l--) { System.out.print(l); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 121 12321 1234321 123454321
Pattern 21:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern21 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j % 2 + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 0 1 0 1 1 0 1 0 1 0 1 0 1
Pattern 22:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern22 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j < i; j++) { System.out.print("0 "); } System.out.print(i + " "); for (int k = i; k < rows; k++) { System.out.print("0 "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 4 0 0 0 0 0 5
Pattern 23:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern23 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(1 + " "); } for (int k = 1; k <= i; k++) { System.out.print(i + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 1 1 1 1 1 1 2 2 1 1 3 3 3 1 4 4 4 4 5 5 5 5 5
Pattern 24:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern24 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = i; j <= rows; j++) { System.out.print(j + " "); } for (int k = rows - 1; k >= i; k--) { System.out.print(k + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 3 4 5 4 3 4 5 4 5
Pattern 25:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern25 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= i; k++) { System.out.print(i + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Pattern 26:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern26 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = rows; i >= 1; i--) { for (int j = i; j < rows; j++) { System.out.print(j + " "); } for (int k = rows - i; k < rows; k++) { System.out.print(5 + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 5 5 5 5 5 4 5 5 5 5 3 4 5 5 5 2 3 4 5 5 1 2 3 4 5
Pattern 27:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern27 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); int k = 1; System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { k=i; for (int j = 1; j <= i; j++) { System.out.print(k + " "); k = k + rows - j; } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 6 3 7 10 4 8 11 13 5 9 12 14 15
Pattern 28:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern28 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); int temp = 1; for(int i=1; i<=rows/2+1; i++) { for(int j=1;j<=i;j++) { System.out.print(temp*j+" "); } System.out.println(); temp++; } for(int i=1; i<=rows/2; i++) { for(int j=1;j<=rows/2+1-i;j++) { System.out.print(temp*j+" "); } System.out.println(); temp++; } } }
Output
Enter the number of rows to print the pattern 7 ** Printing the pattern... ** 1 2 4 3 6 9 4 8 12 16 5 10 15 6 12 7
Pattern 29:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern29 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 0; i < rows; i++) { for (int j = 0; j <= i; j++) { if (j % 2 == 0) { System.out.print(1 + j * rows - (j - 1) * j / 2 + i - j + " "); } else { System.out.print(1 + j * rows - (j - 1) * j / 2 + rows - 1 - i + " "); } } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 9 3 8 10 4 7 11 14 5 6 12 13 15
Pattern 30:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern30 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 0; i < rows; i++) { for (int j = 0; j < rows; j++) { if (j % 2 == 0) System.out.print((rows * (j)) + i + 1 + " "); else System.out.print((rows * (j + 1)) - i + " "); } System.out.print("\n"); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 10 11 20 21 2 9 12 19 22 3 8 13 18 23 4 7 14 17 24 5 6 15 16 25
Pattern 31:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern31 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); int temp = 0; System.out.println("** Printing the pattern... **"); for (int i = rows; i >= 1; i--) { for (int j = rows ; j >= i; j--) { System.out.print(j + " "); temp =j; } for (int k = rows - i+1; k < rows; k++) { System.out.print(temp + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 5 5 5 5 5 5 4 4 4 4 5 4 3 3 3 5 4 3 2 2 5 4 3 2 1
Pattern 32: [ Fibonacci Triangle Pattern ]
package com.javainterviewpoint; import java.util.Scanner; public class Pattern32 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { int a = 0; int b = 1; for (int j = 1; j <= i; j++) { int c = a + b; System.out.print(c + " "); a = b; b = c; } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 2 1 2 3 1 2 3 5 1 2 3 5 8
Pattern 33:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern33 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = rows; i >= 1; i--) { for (int j = i; j <= rows; j++) { System.out.print(j + " "); } for (int k = rows-1; k >= i; k--) { System.out.print(k + " "); } System.out.println(); } for (int i = 2; i <= rows; i++) { for (int j = i; j <= rows; j++) { System.out.print(j + " "); } for (int k = rows-1; k >= i; k--) { System.out.print(k + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 5 4 5 4 3 4 5 4 3 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 3 4 5 4 3 4 5 4 5
Pattern 34:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern34 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { int j = i; for (int k = 1; k <= rows; k++) { System.out.print(j + " "); j++; if (j > rows) j = 1; } System.out.println(); } scanner.close(); } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 4 5 2 3 4 5 1 3 4 5 1 2 4 5 1 2 3 5 1 2 3 4
Pattern 35:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern35 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = i; j <= rows; j++) { System.out.print(j + " "); } for(int k = i-1; k >= 1; k--) { System.out.print(k + " "); } System.out.println(); } scanner.close(); } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 4 5 2 3 4 5 1 3 4 5 2 1 4 5 3 2 1 5 4 3 2 1
Pattern 36:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern36 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { int j = (i * 2) - 1; for (int k = 1; k <= rows; k++) { System.out.print(j + " "); j += 2; if (j > (rows * 2) - 1) j = 1; } System.out.println(); } scanner.close(); } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 3 5 7 9 3 5 7 9 1 5 7 9 1 3 7 9 1 3 5 9 1 3 5 7
Pattern 37:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern37 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { int j = (i * 2) - 1; for (int k = i; k <= rows; k++) { System.out.print(j + " "); j += 2; } for (int l = (i * 2) - 3; l >= 1; l-=2) { System.out.print(l + " "); } System.out.println(); } scanner.close(); } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 3 5 7 9 3 5 7 9 1 5 7 9 3 1 7 9 5 3 1 9 7 5 3 1
Pattern 38:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern38 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j); } for (int j= i*2 ; j < rows*2; j++) { System.out.print(" "); } for (int l = i; l >= 1; l--) { System.out.print(l); } System.out.println(); } scanner.close(); } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 12 21 123 321 1234 4321 1234554321
Pattern 39:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern39 { public static void main(String[] args) { int currentRow = 1; int counter = 1; // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i=1; i<= rows; i++) { if (i % 2 == 0) { int reverse = currentRow + counter - 1; for (int j = 0; j<i; j++) { System.out.print(reverse-- +" "); counter++; } } else { for (int j = 1; j<=i; j++) { System.out.print(counter +" "); counter++; } } System.out.println(); currentRow++; } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 3 2 4 5 6 10 9 8 7 11 12 13 14 15
Pattern 40:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern40 { public static void main(String[] args) { int currentRow = 1; int counter = 1; // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i=1; i<= rows; i++) { if (i % 2 == 0) { for (int j = 1; j<=i; j++) { System.out.print(counter +" "); counter++; } } else { int reverse = currentRow + counter - 1; for (int j = 0; j<i; j++) { System.out.print(reverse-- +" "); counter++; } } System.out.println(); currentRow++; } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 6 5 4 7 8 9 10 15 14 13 12 11
Pattern 41:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern41 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = rows; i >= 1; i--) { for (int j = rows; j >= 1+rows-i; j--) { System.out.print(j); } for (int j= i*2 ; j < rows*2-1; j++) { System.out.print(" "); } for (int l = 1+rows-i; l <=rows; l++) { if(l!=1) System.out.print(l); } System.out.println(); } scanner.close(); } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 543212345 5432 2345 543 345 54 45 5 5
Pattern 42:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern42 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = rows; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j); } for (int j= i*2 ; j < rows*2-1; j++) { System.out.print(" "); } for (int l = i; l >= 1; l--) { if(l!=rows) System.out.print(l); } System.out.println(); } scanner.close(); } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 123454321 1234 4321 123 321 12 21 1 1
Pattern 43:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern43 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); // Top Half for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } for (int k = i - 1; k >= 1; k--) { System.out.print(k + " "); } System.out.println(); } // Bottom Half for (int i = rows-1; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } for (int k = i - 1; k >= 1; k--) { System.out.print(k + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the 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 3 2 1 1 2 3 2 1 1 2 1 1
Pattern 44:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern44 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); // Top Half for (int i = 1; i <= rows; i++) { int temp = i; for (int j = 1; j <= i; j++) { System.out.print(temp + " "); temp = temp + 1; } temp = temp - 2; for (int k = i - 1; k >= 1; k--) { System.out.print(temp + " "); temp = temp - 1; } System.out.println(); } // Bottom Half for (int i = rows - 1; i >= 1; i--) { int temp = i; for (int j = 1; j <= i; j++) { System.out.print(temp + " "); temp = temp + 1; } temp = temp - 2; for (int k = i - 1; k >= 1; k--) { System.out.print(temp + " "); temp = temp - 1; } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 2 3 4 5 4 3 4 5 6 7 6 5 4 5 6 7 8 9 8 7 6 5 4 5 6 7 6 5 4 3 4 5 4 3 2 3 2 1
Pattern 45:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern45 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); int temp = 1; for (int i = 1; i <= rows; i++) { for (int k = 1; k <= i; k++) { System.out.print(temp + " "); } temp++; System.out.println(); } for (int i = rows - 1; i >= 1; i--) { for (int k = i; k >= 1; k--) { System.out.print(temp + " "); } temp++; System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 7 7 7 8 8 9
Pattern 46:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern46 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int k = i; k >= 1; k--) { System.out.print(k + " "); } for (int l = 2; l <= i; l++) { System.out.print(l + " "); } System.out.println(); } for (int i = rows - 1; i >= 1; i--) { for (int k = i; k >= 1; k--) { System.out.print(k + " "); } for (int l = 2; l <= i; l++) { System.out.print(l + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 1 2 3 2 1 2 3 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 3 2 1 2 3 2 1 2 1
Pattern 47:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern47 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(" "); } int val1 = 1; for (int k = 1; k <= i; k++) { System.out.print(val1 + " "); val1 = val1 * 2; } val1 = val1 / 4; for (int l = i - 1; l >= 1; l--) { System.out.print(val1 + " "); val1 = val1 / 2; } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 2 1 1 2 4 2 1 1 2 4 8 4 2 1 1 2 4 8 16 8 4 2 1
Pattern 48:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern48 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = rows; i >= 1; i--) { for (int j = i; j <= rows; j++) { System.out.print(j + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 5 4 5 3 4 5 2 3 4 5 1 2 3 4 5
Pattern 49:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern49 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); int temp = 2; for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { while (!isPrime(temp)) { temp++; } System.out.print(temp + " "); temp++; } System.out.println(); } } public static boolean isPrime(int num) { boolean flag = false; for (int k = 2; k <= num / 2; k++) { if (num % k == 0) { flag = true; break; } } if (flag) return false; return true; } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
Pattern 50:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern50 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); System.out.println("0"); for (int i = rows; i >= 1; i--) { for (int j = i; j <= rows; j++) { System.out.print(j); } System.out.print("0"); for (int k = rows; k >= i; k--) { System.out.print(k); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 0 505 45054 3450543 234505432 12345054321
Pattern 51:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern51 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); int temp = 1; for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(temp + " "); temp++; } int temp1 = temp - 1; for (int k = 2; k <= i; k++) { System.out.print(--temp1 + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 2 4 5 6 5 4 7 8 9 10 9 8 7 11 12 13 14 15 14 13 12 11
Pattern 52:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern52 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); int temp = 1; for (int i = 1; i <= rows; i++) { for (int l = rows; l > i; l--) { System.out.print(" "); } for (int j = 1; j <= i; j++) { System.out.print(temp + " "); temp++; } int temp1 = temp - 1; for (int k = 2; k <= i; k++) { System.out.print(--temp1 + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 2 4 5 6 5 4 7 8 9 10 9 8 7 11 12 13 14 15 14 13 12 11
Pattern 53:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern53 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); int temp = 1; System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int l = rows; l > i; l--) { System.out.print(" "); } for (int j = 1; j <= (i * 2 - 1); j++) { System.out.print((int) Math.pow(temp, 2) + " "); temp++; } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 4 ** Printing the pattern... ** 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256
Pattern 54:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern54 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); int temp = 1; for (int i = 1; i <= rows; i++) { for (int l = rows; l > i; l--) { System.out.print(" "); } for (int j = 1; j <= i; j++) { if (temp < 10) { System.out.print(temp + " "); temp++; } else { temp = 0; System.out.print(temp + " "); temp++; } } int temp1 = temp - 1; for (int k = 2; k <= i; k++) { if (temp1 == 0) { temp1 = 10; System.out.print(--temp1 + " "); } else { System.out.print(--temp1 + " "); } } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 2 3 2 4 5 6 5 4 7 8 9 0 9 8 7 1 2 3 4 5 4 3 2 1
Pattern 55:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern55 { public static void main(String[] args) { int currentRow = 1; int counter = 1; // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int l = rows; l > i; l--) { System.out.print(" "); } if (i % 2 == 0) { int reverse = currentRow + counter - 1; for (int j = 0; j < i; j++) { System.out.print(reverse-- + " "); counter++; } } else { for (int j = 1; j <= i; j++) { System.out.print(counter + " "); counter++; } } System.out.println(); currentRow++; } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 3 2 4 5 6 10 9 8 7 11 12 13 14 15
Pattern 56:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern56 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print((int) Math.pow(j, i) + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 4 ** Printing the pattern... ** 1 1 4 1 8 27 1 16 81 256
Pattern 57:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern57 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 0; i < rows; i++) { int num = 1; for (int j = 0; j <= i; j++) { if(i ==0 || j ==0) num = 1; else num = num * (i - j + 1)/ j; System.out.print(num + " "); } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Pattern 58:
package com.javainterviewpoint; import java.util.Scanner; public class Pattern58 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 0; i <= rows; i++) { int x = 0; int y = 1; System.out.print(y+" "); for (int j = 0; j < i; j++) { int z = x + y; System.out.print(z + " "); x = y; y = z; } System.out.println(); } } }
Output
Enter the number of rows to print the pattern 5 ** Printing the pattern... ** 1 1 1 1 1 2 1 1 2 3 1 1 2 3 5 1 1 2 3 5 8
I hope the above number pattern programs helped you. Do post the patterns which need to be added in the comments. Happy Learning !! 🙂
bibek sahoo says
nice prograammm..keep posting such type of progrmm..
Saranya says
Hi ,
Please anyone help me for this bellow program.
8 80
12 120 1200
16 160 1600 16000
javainterviewpoint says
Here you go
Amitabh Sinha says
1
2 6
3 7 10
4 8 11 13
javainterviewpoint says
Have added your pattern – Pattern 27
Sarthak says
Plz help me out by this program wirhin 9 O clock Today,
#####
####
###
##
#
javainterviewpoint says
Here you go
for(int i=5; i>=1; i–){
for(int j=i; j>=1; j–){
System.out.print(“#”);
}
System.out.println();
}
javainterviewpoint says
Have added your pattern – Pattern 28
Jyothi says
Sir can you please post the code for this:
1
2 9
3 8 10
4 7 11 14
5 6 12 13 15
javainterviewpoint says
Have added your pattern – Pattern 29
Deblina Sarkar says
Plz help me out to do this program…..
5 5 5 5 5
5 4 4 4 4
5 4 3 3 3
5 4 3 2 2
5 4 3 2 1
javainterviewpoint says
Have added your pattern – Pattern 31
Arpitha D says
1
3*2
6*5*4
10*9*8*7
plz help to get this output
javainterviewpoint says
Here you go
Haripriya says
5
4 5 4
3 4 5 4 3
2 3 4 5 4 3 2
1 2 3 4 5 4 3 2 1
2 3 4 5 4 3 2
3 4 5 4 3
4 5 4
5
Sir, can you please post the code for the above output pattern?
javainterviewpoint says
Have added your pattern – Pattern 33
Haripriya says
1
1 2 3
1 2 3 5
1 2 3 5 8
1 2 3 5 8 13
Sir, can you please post the code the above output pattern?
javainterviewpoint says
Here you go
Kumar ashutosh says
9
7 9
5 7 9
3 5 7 9
1 3 5 7 9
javainterviewpoint says
Here you go
Haripriya says
Sir, can you please post the code the below output pattern?
5
4 5 4
3 4 5 4 3
2 3 4 5 4 3 2
1 2 3 4 5 4 3 2 1
2 3 4 5 4 3 2
3 4 5 4 3
4 5 4
5
Haripriya says
Sorry sir, I have given the wrong pattern. Actually, I need the output for the pattern given below. Thanks in advance.
5
4 5 4
3 4 5 4 3
2 3 4 5 4 3 2
1 2 3 4 5 4 3 2 1
2 3 4 5 4 3 2
3 4 5 4 3
4 5 4
5
Abdinasir Ismail Ali says
Sir can you help me the code for this
*
**
*
****
*
******
Please
javainterviewpoint says
for( int i=1; i<=6; i++) { if(i%2!=0) System.out.print("*"); else { for(int j=1; j<=i; j++) System.out.print("*"); } System.out.println(); }
Shahi says
1 2 3 4 5
2 2 3 4 5
3 3 3 4 5
4 4 4 4 5
5 5 5 5 5
how create this type of pattern pls help sir
javainterviewpoint says
Here you go
for(int i=1; i<=5;i++) { for(int j=1;j<=5; j++) { if(j<=i) System.out.print(i); else System.out.print(j); } System.out.println(); }
Tejal says
2
3 5
7 11 13
17 19 23 29
31 37 41 43 47 Sir, can you please post the code for the above output pattern?
javainterviewpoint says
Here you go
static int prime = 2;
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { boolean flag = checkPrime(prime); while(flag) { ++prime; flag = checkPrime(prime); if(!flag) break; } System.out.print(prime+" "); prime++; } System.out.println(); } } public static boolean checkPrime(int num) { boolean flag = false; for (int i = 2; i <= num / 2; ++i) { if (num % i == 0) { flag = true; break; } } return flag; }
Harshit says
Plzzz do this
*
*#
*#*
*#*#
*#*#*
javainterviewpoint says
Here you go
public static void main(String[] args)
{
int n=5;
for(int i = 0; i < 5; i++) { for(int j = 0; j <= i; j++) { if(j % 2 == 0) System.out.print("*"); else System.out.print("#"); } System.out.print("\n"); } }
heerne says
need this pattern please
1
4 1
9 4 1
16 9 4 1
25 16 9 4 1
javainterviewpoint says
Here you go
public static void main(String[] args)
{
for (int i = 1;i <= 5;i++) { for (int j = i;j >= 1;j--)
{
System.out.print(j * j + " ");
}
System.out.println();
}
}
Dhanya Vijayan says
Can anyone help me with the code
1
1 12
1 12 123
1 12 123 1234
1 12 123 1234 12345
javainterviewpoint says
Here you go
Abhyankar says
1***
12**
123*
1234
How to do this?
javainterviewpoint says
Here you go
public static void main(String[] args)
{
for (int i = 1;i <= 4;i++) { for (int j=1; j<=i; j++) { System.out.print(j+" "); } for (int k=3; k>=i; k--)
{
System.out.print("* ");
}
System.out.println();
}
}
Raj Gupta says
1
3 1
5 3 1
7 5 3 1
9 5 7 3 1
Help me out this pattern
javainterviewpoint says
Here you go
public static void main(String[] args)
{
for (int i = 1;i <= 5;i++) { int temp = i*2 -1; for (int j = 1; j <=i ; j++) { System.out.print(temp+" "); temp= temp -2; } System.out.println(); } }
Asish Kumar says
how to print following this pattern using for loop
1
2
3
4
5
javainterviewpoint says
Here you go
public static void main(String[] args)
{
for (int i = 1;i <= 5;i++) { System.out.println(i); } }
kartik kumar verma says
1
2 3
3 4 5
4 5 6 7
javainterviewpoint says
Here you go
public static void main(String[] args)
{
for (int i = 1;i <= 5;i++) { int temp = i; for (int j = 1; j <=i ; j++) { System.out.print(temp+" "); temp= temp +1; } System.out.println(); } }
Renuka says
*****
0000
***
00
*
pls solve this
javainterviewpoint says
Here you go
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++) { for (int j = 5; j >= i; j--)
{
if (i % 2 == 0)
{
System.out.print("0 ");
} else
{
System.out.print("* ");
}
}
System.out.println();
}
}
AbirJash says
Sir can you help me
1
1 1
1 0 1
1 0 0 1
1 0 0 0 1
javainterviewpoint says
Here you go
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { if(j ==1 || j == i) System.out.print("1"); else System.out.print("0"); } System.out.println(); }
AJAY says
please TELL how to print this patttern
A
A B A
A B C B C
A B C D C B A
A B C D E D C B A
javainterviewpoint says
Check out the Pattern 14 of Alphabet Pattern Program
https://www.javainterviewpoint.com/alphabet-pattern-program/
Shreya says
could you help me with this patter
1 3 5 7 9
3 5 7 9 1
5 7 9 1 3
7 9 1 3 5
9 1 3 5 7
javainterviewpoint says
Have added your pattern – Pattern 36
Shreya says
thank you so much sir.
Vineesha Balne says
Hi Sir,
Can you please let me know how to print this pattern?
1
12
123
1234
12345
javainterviewpoint says
Here you go
SIBA says
write a program in java to accept a string from the user . pass the string to a function change (string str) which displays the first character of each word after changing the case,sample input:- delhi public school
Out Put:-D
P
S
javainterviewpoint says
Here you go
Mithal says
Can u. Please let me know how to print this program ?
*1234
1*123
12*12
123*1
javainterviewpoint says
Here you go
Saiesh says
*
**
***
****
*****
******
******
*****
****
***
**
*
Please print above pattern for n=6. And please tell us how can we improve ourselves in such problems. What do we practice to achieve your level Sir.
javainterviewpoint says
I have created a separate collection for star pattern programs
https://www.javainterviewpoint.com/star-pattern-programs-in-java/
The pattern which you have asked is at Pattern 9
Just keep practicing for loops and you will be stronger soon:)
Mahesh says
1
1*
1*3
1*3*
1*3*5
Code for this please
javainterviewpoint says
Here you go
Padmashekara Pathyare Shetty says
Can you please help me to print this program ?
abcdedcba
abcdcba
abcba
aba
a
Please by tomorrow afternoon
javainterviewpoint says
Added your pattern in the Alphabet Pattern – Pattern 28
Padmashekara Pathyare Shetty says
Can you please help me to print this pattern?
ABCDE
BCDEF
CDEFG
DEFGH
Please by tomorrow afternoon
javainterviewpoint says
Added your pattern in the Alphabet Pattern Post – Pattern 27
Padmashekara Pathyare Shetty says
Write a program in Java to accept a String in upper case and print the words which have at least a pair of consecutive letters
sample input: MODEM IS AN ELECTRONIC DEVICE
sample output : MODEM
DEVICE
Please sir help me wit this question
javainterviewpoint says
Can you please brief a little more, you want consecutive characters or is it fine to display word which has characters occurring more than once
Padmashekara Shetty says
I want the consecutive characters
Eg : moDEm
DEvice
No. Of words : 2
javainterviewpoint says
It was already there in the Number pattern program, follow the below link
https://www.javainterviewpoint.com/number-pattern-programs-in-java/#comment-25725
mahesh says
Code for this pattern
*
123
*****
1234567
Mahesh says
54321
4321
321
21
1
This pattern also please
javainterviewpoint says
Here you go
Srinivas says
123454321
1234321
12321
121
1
Write a program to reverse this pyramid
javainterviewpoint says
Here you go
Rajat goel says
#
#1#
#23#
#456#
javainterviewpoint says
Here you go
Raj says
1
3. 5
7. 9. 11
13 15. 17. 19
javainterviewpoint says
Do you need the dots as well.. If yes why some of the dots are missing after the numbers ? is there any logic behind it?
Pradip Kumar Das says
Please write the BlueJ code for the following pattern by today.
ABCDE
ABCDA
ABCAB
ABABC
AABCD
javainterviewpoint says
Here you go
Rak says
1
0 1
0 1 0
1 0 1 0
javainterviewpoint says
Here you go
mahesh says
I
I Like
I Like Very
I Like Very Much
I Like Very Much Java
javainterviewpoint says
Here you go
Anas Siddiqui says
Plzzz help me out for this pattern ….plzzz —
12345
2345
345
45
5
45
345
2345
12345
javainterviewpoint says
Here you go
Nihar says
please help me with this program
Write a program to input a sentence.convert the sentence into upper case.display
the words along with frequency of the words which have at least a pair of consecutive letters
sample input :MODEM IS AN ELECTRONIC DEVICE
sample output:MODEM
DEVICE
NO OF WORDS CONTAINING CONSECUTIVE LETTERS : 2
javainterviewpoint says
Here you go
Pintu says
1
234
56789
10111213141516
javainterviewpoint says
Here you go
Parikshit Naskar says
Sir
I face a Java problem. Please solve the problem .
* * * *
* * *
* * * *
* * *
* * * *
* * *
* * * *
javainterviewpoint says
Added your pattern in the Alphabet Pattern Post – Pattern 35
VIGNESHWARAN says
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
Help me
javainterviewpoint says
Here you go
Sachin Batra says
Explaining little more. first array digit is 6 so java program should print 6 asterisk then 2, 3 like this. And if its 9 then print nine starts. This should be bottom to top approach
javainterviewpoint says
Can you brief me a little more on this, let me put my understanding first value is 6 so it should print 6 asterik from bottom to top, now what to 2,3 does there how it adds up space there? what is the logic behind it? also, post the pattern once again wrapped in <pre></pre> tag.
Sachin batra says
Yes asterik would print according to arrays value. first value is 6 it should print 6 asterik and so on…
int ar[] = {3,2,4,5,6}
*
**
***
* ***
*****
*****
javainterviewpoint says
Hope this is what you are looking for, the first column will have 3 asterisks, the second column will have 2 asterisks, the third column will have 4 asterisks and so on…
carol denvers says
FIBONACCI PATTERN (PATTERN 4)
0
1 1
2 3 5
8 13 21 34
javainterviewpoint says
Here you go
ABREETH says
HELLO SIR, PLEASE HELP ME TO SOLVE THIS
*
*
* *
* *
* * *
* *
* *
*
*
ABREETH says
Sir, i need a program for the same pattern 6 but the pyramid should be tilted 90 degree. kindly help me out
javainterviewpoint says
Here you go
anonymous says
sir please do pattern 38 upside down
javainterviewpoint says
Here you go
anonymous says
Sir please do this pattern
ABCD1
BCD12
CD123
D1234
javainterviewpoint says
Your pattern
vineeth says
Sir i need help in this pattern
1
2 4
1 3 5
2 4 6 8
1 3 5 7 9
javainterviewpoint says
Below goes the pattern
anonymous says
Sir please do this for me.thank you
1
2 2
3 3 3
4 4 4 4
anonymous says
Sir please solve this in the form of a triangle
javainterviewpoint says
Take Pattern 6 of Number Pattern Program and modify the third loop (k loop) instead of printing k print i
Just change System.out.print(k + ” “); to System.out.print(i + ” “);
anonymous says
Sir please do pattern 2 in the form of a triangle
gajju says
12345
12341
12312
12123
11234
pls help me for this pattern
javainterviewpoint says
Here you go
Meghna says
11111
22222
33333
444444
55555
Sir can you help me with this pattern…
javainterviewpoint says
Here you go
Pheonix says
Hi, I need something to resemble a snake pattern like this.
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
javainterviewpoint says
Here you go
Hasnain says
Hi,I need someone to resolve patttern like this:-
1
3 5
7 9 11
1 3 5 7
9 11 1 3 5
7 9 11 1 3 5
javainterviewpoint says
Here you go
Jainendra says
sorry wrong pattern
9 7 5 3 1
7 5 3 1
5 3 1
3 1
1
javainterviewpoint says
Here you go
mohseen says
1
1 4
1 8 27
javainterviewpoint says
Your pattern
krishna says
1
2 3 2
4 5 6 5 4
7 8 9 0 9 8 7
1 2 3 4 5 4 3 2 1
6 7 8 9 0 1 0 9 8 7 6
hello sir, anyone try this pattern send me the code.
javainterviewpoint says
Have added you pattern – Pattern 54
DEVIL says
PLEASE HELP ME WITH THIS:-
A B C D E D C B A
A B C D 1 D C B A
A B C 1 2 1 C B A
A B 1 2 3 2 1 B A
A 1 2 3 4 3 2 1 A
A B 1 2 3 2 1 B A
A B C 1 2 1 C B A
A B C D 1 D C B A
A B C D E D C B A
javainterviewpoint says
Here you go
Shreya gupta says
Can anyone plz help me with this :
9
79
579
3579
13579
And Also with
99999
77777
55555
33333
11111
javainterviewpoint says
Here you go
Pattern1
Pattern2
Devesh Kumar says
Can anyone plz help me with this :
1
1*2
1*2*3
1*2*3*4
1*2*3*4*5
javainterviewpoint says
Your pattern
Devesh Kumar says
And one more with:
1
2 3
4 5 6
7 8 9 1
2 3 4 5 6
javainterviewpoint says
Your program
arshdeep says
sir can you please solve this
* * * * * *
* * * *
* *
* *
* * * *
* * * * * *
javainterviewpoint says
I didn’t clearly get the pattern, guess this is what you are looking for Pattern 27 of Star Pattern program
Devid parker says
Write a Java program to display the number rhombus structure. Go to the editor
Input the number: 7 Expected Output :
1
212
32123
4321234
543212345
65432123456
7654321234567
65432123456
543212345
4321234
32123
212
1
Write a Java program to display the following character rhombus structure.
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
javainterviewpoint says
Here you go
Pattern 1
Pattern 2
Shobhan Dasthakur says
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
javainterviewpoint says
Have added you pattern – Pattern 57
Sukumar kyra says
Can u please tell how to print the following program
1
2*3
4*5*6
7*8*9*10
4*5*6
2*3
1
By giving input as 4
javainterviewpoint says
R karthik says
1
1 2
2 2 3
3 3 3 4
4 4 4 4 5
5 5 5 5 5 6
Sir how to print above pattern
javainterviewpoint says
Here you go
Ishwar Ram says
1 *
1 2 * *
1 2 3 * * *
1 2 3 4 * * * *
1 2 3 4 5 * * * * *
How to create this type pattern Sir?please help me sir
javainterviewpoint says
Here you go
Krishna says
1
2 1
1 2 3
4 3 2 1
1 2 3 4 5
6 5 4 3 2 1
Please help me sir also this program
javainterviewpoint says
Here you go
snow says
1 # #
$ 1 #
$ $ 1
please solve this
javainterviewpoint says
Here you go
Rohit Raj says
Plzzzz print this pattern:
1 2 3 4 5
5 4 3 2 1
1 2 3 4 5
5 4 3 2 1
1 2 3 4 5
javainterviewpoint says
Here you go
Subham ghosh says
can you please tell the code of this prattern
1 1 1 1 1
3 3 3 3
5 5 5
7 7
9
javainterviewpoint says
Here you go
Rohit says
Plzzzz…. print this pattern
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
javainterviewpoint says
Here you go
Rohit says
Thanks
Rohit says
Plzzz…. print this pattern
1
3 3
5 5 5
7 7 7 7
.
.
.
.
n rows
javainterviewpoint says
Here you go
Rohit says
Plzzz….. Print this pattern
1
2 3
4 5 6
7 8 9 10
.
.
.
.
n rows
javainterviewpoint says
Here you go
Rohit says
Plzzz….. Print this pattern
1
0 0
1 1 1
0 0 0 0
1 1 1 1 1
javainterviewpoint says
Here you go
Rohit says
Plzzz…… Print this pattern
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
.
.
.
.
n rows
javainterviewpoint says
Here you go
parikshit naskar says
pls solve the problem
1 2 3 4 5
1 2 3 4 4
1 2 3 3 3
1 2 2 2 2
1 1 1 1 1
parikshit naskar says
Pls solve the problem of the above . It is very urgent to me.