3 4 25 66 133 232 369 550 Continue Pattern Continuing the Pattern

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

Number Pattern Programs in Java 5

Number Pattern Programs in Java 8

Number Pattern Programs in Java 10

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 !! 🙂

markovichyoutbreters.blogspot.com

Source: https://www.javainterviewpoint.com/number-pattern-programs-in-java/

0 Response to "3 4 25 66 133 232 369 550 Continue Pattern Continuing the Pattern"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel