All Java Pattern Program List To Grow Coding Logical Skills.


Hello Dear Reader, in this article I will provide you All Java Pattern Program List. which is helps you to improve your coding skills logically? if you are trying to improve your coding skills. definitely, these programs help you.  

Every interview has a coding round. that is also an important part of interviews. if you have good skills in programming. on that round, you need to show your coding skills to crack the interview.

It also depends on your logical capability. how much you can write short and effective code. and Java Pattern Programs are also the hardest part of the interview.

Now you don't need to worry about the solution of all these pattern programs of java.  Here I will add all the questions and solutions to the pattern.

  • if you have more Java Pattern Programs then you need to share with Others so Please add more patterns in the comment section.

List of Number Pattern Programs In Java

"java program patterns" "java programs for patterns" "all pattern program in java" "java star pattern program" "star pattern program java" "java pattern program" "design pattern program in java" "pattern program java" "number pattern program in java" "alphabet pattern program in java"


Pattern 1:- Number Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern1  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = 1; j <= i; j++)  
16:   {  
17:   System.out.print(j + " ");  
18:   }  
19:   System.out.println();  
20:   }  
21:   }  
22:  }  

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  


Program Summary:-


Pattern 2:- Number solution program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern2  
4:  {  
5:      public static void main(String[] args)  
6:     {  
7:         // Create a new Scanner object  
8:         Scanner scanner = new Scanner(System.in);  
9:         // Get the number of rows from the user  
10:        System.out.println("Enter the number of rows to print the pattern");  
11:        int rows = scanner.nextInt();  
12:        System.out.println("** Printing the pattern...**");  
13:        for (int i = 1; i <= rows; i++)  
14:         {  
15:            for (int j = 1; j <= i; j++)  
16:              {  
17:                 System.out.print(i + " ");  
18:              }  
19:              System.out.println();  
20:         }  
21:      }  
22:  }  

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:- Number Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern3  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = 1; j <= i; j++)  
16:   {  
17:   System.out.print(j + " ");  
18:   }  
19:   System.out.println();  
20:   }  
21:   for (int i = rows; i >= 1; i--)  
22:   {  
23:   for (int j = 1; j < i; j++)  
24:   {  
25:   System.out.print(j + " ");  
26:   }  
27:   System.out.println();  
28:   }  
29:   }  
30:  }  

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:- K Shape Numbers Patten Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern4  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = rows; i >= 1; i--)  
14:   {  
15:   for (int j = 1; j <= i; j++)  
16:   {  
17:   System.out.print(j + " ");  
18:   }  
19:   System.out.println();  
20:   }  
21:   for (int i = 1; i <= rows; i++)  
22:   {  
23:   for (int j = 1; j <= i; j++)  
24:   {  
25:   System.out.print(j + " ");  
26:   }  
27:   System.out.println();  
28:   }  
29:   }  
30:  }  

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:- K Shape Ascending Order Numbers Patten Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern5  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = rows; i >= 1; i--)  
14:   {  
15:   for (int j = i; j >= 1; j--)  
16:   {  
17:   System.out.print(j + " ");  
18:   }  
19:   System.out.println();  
20:   }  
21:   for (int i = 1; i <= rows; i++)  
22:   {  
23:   for (int j = i; j >= 1; j--)  
24:   {  
25:   System.out.print(j + " ");  
26:   }  
27:   System.out.println();  
28:   }  
29:   }  
30:  }  

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:- Numeric Tringle pattern in java.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern6  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = rows; j > i; j--)  
16:   {  
17:   System.out.print(" ");  
18:   }  
19:   for (int k = 1; k <= i; k++)  
20:   {  
21:   System.out.print(k + " ");  
22:   }  
23:   System.out.println();  
24:   }  
25:   }  
26:  }  

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:- Downward Descending Numeric pattern in java.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern7  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = rows; j >= i; j--)  
16:   {  
17:   System.out.print(j + " ");  
18:   }  
19:   System.out.println();  
20:   }  
21:   }  
22:  }  

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:- Descending Numeric pattern.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern8  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = rows; i >= 1; i--)  
14:   {  
15:   for (int j = rows; j >= i; j--)  
16:   {  
17:   System.out.print(j + " ");  
18:   }  
19:   System.out.println();  
20:   }  
21:   }  
22:  }  

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:- Downward Ascending Numeric Pattern In Java.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern9  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = rows; i >= 1; i--)  
14:   {  
15:   for (int j = 1; j <= i; j++)  
16:   {  
17:   System.out.print(j + " ");  
18:   }  
19:   System.out.println();  
20:   }  
21:   }  
22:  }  

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:- Design Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern10  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   int k = 1;  
13:   System.out.println("** Printing the pattern... **");  
14:   for (int i = 1; i <= rows; i++)  
15:   {  
16:   for (int j = 1; j <= i; j++)  
17:   {  
18:   System.out.print(k + " ");  
19:   k++;  
20:   }  
21:   System.out.println();  
22:   }  
23:   }  
24:  }  

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:- Right Tringle Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern11  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = i; j >= 1; j--)  
16:   {  
17:   System.out.print(j + " ");  
18:   }  
19:   System.out.println();  
20:   }  
21:   }  
22:  }  

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:- Count Lins with Line Space Right Triangle Design Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern12  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   int temp = i;  
16:   for (int j = i; j >= 1; j--)  
17:   {  
18:   System.out.print(temp + " ");  
19:   temp = temp + rows;  
20:   }  
21:   System.out.println();  
22:   }  
23:   }  
24:  }  

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:- Pascal's Triangle Design Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern13  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = rows; j > i; j--)  
16:   {  
17:   System.out.print(" ");  
18:   }  
19:   int temp = 1;  
20:   for (int k = 1; k <= i; k++)  
21:   {  
22:   System.out.print(temp + " ");  
23:   temp = temp * (i - k) / (k);  
24:   }  
25:   System.out.println();  
26:   }  
27:   }  
28:  }  

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:- First half and Second Half Numeric Design Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern14  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = 1; j <= i; j++)  
16:   {  
17:   System.out.print(j + " ");  
18:   }  
19:   for (int k = i - 1; k >= 1; k--)  
20:   {  
21:   System.out.print(k + " ");  
22:   }  
23:   System.out.println();  
24:   }  
25:   }  
26:  }  

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:- Revers Numeric Triangle Design Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern15  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = 1; j < i; j++)  
16:   {  
17:   System.out.print(" ");  
18:   }  
19:   for (int k = 1; k <= rows - i + 1; k++)  
20:   {  
21:   System.out.print(k + " ");  
22:   }  
23:   System.out.println();  
24:   }  
25:   }  
26:  }  

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:- Revers Numeric Triangle Design Pattern Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern16  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = rows; j > i; j--)  
16:   {  
17:   System.out.print(" ");  
18:   }  
19:   for (int k = 1; k <= i; k++)  
20:   {  
21:   System.out.print(k + " ");  
22:   }  
23:   System.out.println();  
24:   }  
25:   for (int i = 1; i <= rows; i++)  
26:   {  
27:   for (int j = 1; j <= i; j++)  
28:   {  
29:   System.out.print(" ");  
30:   }  
31:   for (int k = 1; k <= rows - i; k++)  
32:   {  
33:   System.out.print(k + " ");  
34:   }  
35:   System.out.println();  
36:   }  
37:   }  
38:  }  

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:- Revers K Shape Numeric Design Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern17  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = 1; j < i; j++)  
16:   {  
17:   System.out.print(" ");  
18:   }  
19:   for (int k = i; k <= rows; k++)  
20:   {  
21:   System.out.print(k);  
22:   }  
23:   System.out.println();  
24:   }  
25:   for (int i = rows; i >= 1; i--)  
26:   {  
27:   for (int j = 1; j < i; j++)  
28:   {  
29:   System.out.print(" ");  
30:   }  
31:   for (int k = i; k <= rows; k++)  
32:   {  
33:   System.out.print(k);  
34:   }  
35:   System.out.println();  
36:   }  
37:   }  
38:  }  

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:- Diamond Numeric Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern18  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = 1; j < i; j++)  
16:   {  
17:   System.out.print(" ");  
18:   }  
19:   for (int k = i; k <= rows; k++)  
20:   {  
21:   System.out.print(k + " ");  
22:   }  
23:   System.out.println();  
24:   }  
25:   for (int i = rows; i >= 1; i--)  
26:   {  
27:   for (int j = 1; j < i; j++)  
28:   {  
29:   System.out.print(" ");  
30:   }  
31:   for (int k = i; k <= rows; k++)  
32:   {  
33:   System.out.print(k + " ");  
34:   }  
35:   System.out.println();  
36:   }  
37:   }  
38:  }  

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:- Diamond Numeric  Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern19  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = rows; i >= 1; i--)  
14:   {  
15:   for (int j = 1; j < i; j++)  
16:   {  
17:   System.out.print(" ");  
18:   }  
19:   for (int k = i; k <= rows; k++)  
20:   {  
21:   System.out.print(k + " ");  
22:   }  
23:   System.out.println();  
24:   }  
25:   }  
26:  }  

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:- First and Second Half Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern20  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = rows; j > i; j--)  
16:   {  
17:   System.out.print(" ");  
18:   }  
19:   for (int k = 1; k <= i; k++)  
20:   {  
21:   System.out.print(k);  
22:   }  
23:   for (int l = i - 1; l >= 1; l--)  
24:   {  
25:   System.out.print(l);  
26:   }  
27:   System.out.println();  
28:   }  
29:   }  
30:  }  

Output:-
 Enter the number of rows to print the pattern  
 5  
 ** Printing the pattern... **  
     1  
    121  
   12321  
  1234321  
 123454321  

Pattern 21:- Zero And One Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern21  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = 1; j <= i; j++)  
16:   {  
17:   System.out.print(j % 2 + " ");  
18:   }  
19:   System.out.println();  
20:   }  
21:   }  
22:  }  

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:- Rectangle Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern22  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = 1; j < i; j++)  
16:   {  
17:   System.out.print("0 ");  
18:   }  
19:   System.out.print(i + " ");  
20:   for (int k = i; k < rows; k++)  
21:   {  
22:   System.out.print("0 ");  
23:   }  
24:   System.out.println();  
25:   }  
26:   }  
27:  }  

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:- Downward Revers Number Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern23  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = rows; j > i; j--)  
16:   {  
17:   System.out.print(1 + " ");  
18:   }  
19:   for (int k = 1; k <= i; k++)  
20:   {  
21:   System.out.print(i + " ");  
22:   }  
23:   System.out.println();  
24:   }  
25:   }  
26:  }  

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:- First And Second Half Downward Numeric Pattern Program in java.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern24  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 1; i <= rows; i++)  
14:   {  
15:   for (int j = i; j <= rows; j++)  
16:   {  
17:   System.out.print(j + " ");  
18:   }  
19:   for (int k = rows - 1; k >= i; k--)  
20:   {  
21:   System.out.print(k + " ");  
22:   }  
23:   System.out.println();  
24:   }  
25:   }  
26:  }  

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:- Same Number Triangle  Pattern Program in java.

1:  Pattern 25:  
2:  package com.javainterviewpoint;  
3:  import java.util.Scanner;  
4:  public class Pattern25  
5:  {  
6:   public static void main(String[] args)  
7:   {  
8:   // Create a new Scanner object  
9:   Scanner scanner = new Scanner(System.in);  
10:   // Get the number of rows from the user  
11:   System.out.println("Enter the number of rows to print the pattern ");  
12:   int rows = scanner.nextInt();  
13:   System.out.println("** Printing the pattern... **");  
14:   for (int i = 1; i <= rows; i++)  
15:   {  
16:   for (int j = rows; j > i; j--)  
17:   {  
18:   System.out.print(" ");  
19:   }  
20:   for (int k = 1; k <= i; k++)  
21:   {  
22:   System.out.print(i + " ");  
23:   }  
24:   System.out.println();  
25:   }  
26:   }  
27:  }  


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:- Downward Rectangle Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern26  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = rows; i >= 1; i--)  
14:   {  
15:   for (int j = i; j < rows; j++)  
16:   {  
17:   System.out.print(j + " ");  
18:   }  
19:   for (int k = rows - i; k < rows; k++)  
20:   {  
21:   System.out.print(5 + " ");  
22:   }  
23:   System.out.println();  
24:   }  
25:   }  
26:  }  

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:- Numeric Tringal Pattern Program in java.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern27  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   int k = 1;  
13:   System.out.println("** Printing the pattern... **");  
14:   for (int i = 1; i <= rows; i++)  
15:   {  
16:   k=i;  
17:   for (int j = 1; j <= i; j++)  
18:   {  
19:   System.out.print(k + " ");  
20:   k = k + rows - j;  
21:   }  
22:   System.out.println();  
23:   }  
24:   }  
25:  }  

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:- Right Pascal's Triangle With Adding Double Value Pattern Program in java.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern28  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   int temp = 1;  
14:   for(int i=1; i<=rows/2+1; i++)  
15:   {  
16:   for(int j=1;j<=i;j++)  
17:   {  
18:   System.out.print(temp*j+" ");  
19:   }  
20:   System.out.println();  
21:   temp++;  
22:   }  
23:   for(int i=1; i<=rows/2; i++)  
24:   {  
25:   for(int j=1;j<=rows/2+1-i;j++)  
26:   {  
27:   System.out.print(temp*j+" ");  
28:   }  
29:   System.out.println();  
30:   temp++;  
31:   }  
32:   }  
33:  }  


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:- Zic-Zake Values  Triangle Pattern Program in java.


1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern29  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 0; i < rows; i++)  
14:   {  
15:   for (int j = 0; j <= i; j++)  
16:   {  
17:   if (j % 2 == 0)  
18:   {  
19:   System.out.print(1 + j * rows - (j - 1) * j / 2 + i - j +  
20:  " ");  
21:   } else  
22:   {  
23:   System.out.print(1 + j * rows - (j - 1) * j / 2 + rows -  
24:  1 - i + " ");  
25:   }  
26:   }  
27:   System.out.println();  
28:   }  
29:   }  
30:  }  

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:- Square Rectangle Pattern Program in java.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern30  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   System.out.println("** Printing the pattern... **");  
13:   for (int i = 0; i < rows; i++)  
14:   {  
15:   for (int j = 0; j < rows; j++)  
16:   {  
17:   if (j % 2 == 0)  
18:   System.out.print((rows * (j)) + i + 1 + " ");  
19:   else  
20:   System.out.print((rows * (j + 1)) - i + " ");  
21:   }  
22:   System.out.print("\n");  
23:   }  
24:   }  
25:  }  

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:- Rectangle Program.

1:  package com.javainterviewpoint;  
2:  import java.util.Scanner;  
3:  public class Pattern31  
4:  {  
5:   public static void main(String[] args)  
6:   {  
7:   // Create a new Scanner object  
8:   Scanner scanner = new Scanner(System.in);  
9:   // Get the number of rows from the user  
10:   System.out.println("Enter the number of rows to print the pattern ");  
11:   int rows = scanner.nextInt();  
12:   int temp = 0;  
13:   System.out.println("** Printing the pattern... **");  
14:   for (int i = rows; i >= 1; i--)  
15:   {  
16:   for (int j = rows ; j >= i; j--)  
17:   {  
18:   System.out.print(j + " ");  
19:   temp =j;  
20:   }  
21:   for (int k = rows - i+1; k < rows; k++)  
22:   {  
23:   System.out.print(temp + " ");  
24:   }  
25:   System.out.println();  
26:   }  
27:   }  
28:  }  

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  

Admin Words:- I am tried to solve all these java pattern programs in a simple way. This list helps you to make it easy to understand every design pattern program in java. 
If you find any error in this java pattern program. please feel free to ask in the comment below of this post.

Recommended:- 

Post a Comment

0 Comments