Some Java Pattern Programs To Practice(Part 3)

Codynn
10 Min Read
Contents: Click for quick access
21. Write a program to display following pattern .           1           1 0           1 0 1           1 0 1 0            1 0 1 0 1 ,22. Write a program to display following pattern.            1 0 1 0 1            1 0 1 0           1 0 1           1 0            1  , 23. Write a program to display following pattern.            1            0 1           1 0 1           0 1 0 1            1 0 1 0 1  , 24. Write a program to display following pattern.            1 2 3 4 5            2 4 6 8 10           3 6 9 12 15           4 8 12 16 20            5 10 15 20 25 ,25. Write a program to display following pattern.         1            1 2            1 2 3            1 2 3 4            1 2 3 4 5            1 2 3 4 5 6 7            1 2 3 4 5 6            1 2 3 4 5            1 2 3 4            1 2 3            1 2            1  , 26. Write a program to display following pattern .           1            1 2 1            1 2 3 2 1            1 2 3 4 3 2 1            1 2 3 4 5 4 3 2 1            1 2 3 4 5 6 5 4 3 2 1            1 2 3 4 5 6 7 6 5 4 3 2 1  , 27. Write a program to display following pattern.            1 2 3 4 5 6 7            1 2 3 4 5 6            1 2 3 4 5            1 2 3 4            1 2 3            1 2             1             1 2            1 2 3             1 2 3 4             1 2 3 4 5            1 2 3 4 5 6            1 2 3 4 5 6 7  ,28. Write a program to display following pattern.            1234567              234567                34567                  4567                    567                      67                        7                      67                    567                  4567                34567              234567            1234567  , 29. Write a program to display following pattern.            1            2 1            3 2 1            4 3 2 1            5 4 3 2 1             6 5 4 3 2 1            7 6 5 4 3 2 1  , 30. Write a program to display following pattern.            1  2  3  4  5  6  7               2  3  4  5  6  7                3  4  5  6  7                  4  5  6  7                    5  6  7                      6  7                        7                      6  7                    5  6  7                  4  5  6  7                3  4  5  6  7              2  3  4  5  6  7            1  2  3  4  5  6  7  

I’ve included a list of some of the Java programs below. You may also view all of the Java programs on our mobile app. I strongly advise you to use our mobile app for a better experience.

Please click the link to get our app–> https://play.google.com/store/apps/details?id=com.allbachelor.javaapp&hl=en&gl=US

21. Write a program to display following pattern .   

        1   

        1 0   

        1 0 1   

        1 0 1 0    

        1 0 1 0 1 ,

import java.util.Scanner; 
 
class Patterns { 
   public static void main(String[] args) { 
       Scanner sc = new Scanner(System.in); 
       System.out.println("How many rows do you want this pattern to have?"); 
       int row = sc.nextInt(); 
       for (int i = 1; i < = 5; i++) { 
           for (int j = 1; j < =i ; j++) { 
               System.out.print(j%2); 
           } 
 
           System.out.println(); 
           } 
 
       } 
 
   } 

22. Write a program to display following pattern.    

        1 0 1 0 1    

        1 0 1 0   

        1 0 1   

        1 0    

        1  ,

import java.util.Scanner;

class Patterns {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("How many rows do you want this pattern to have?");
       int row = sc.nextInt();
       for (int i = 1; i < = 5; i++) {
           for (int j = 5; j >=i ; j--) {
               System.out.print(j%2);
           }

           System.out.println();
           }

       }

 23. Write a program to display following pattern.    

        1    

        0 1   

        1 0 1   

        0 1 0 1    

        1 0 1 0 1  ,

import java.util.Scanner; 
 
class Patterns { 
   public static void main(String[] args) { 
       Scanner sc = new Scanner(System.in); 
       System.out.println("How many rows do you want this pattern to have?"); 
       int row = sc.nextInt(); 
       for (int i = 1; i < = 5; i++) { 
           for (int j = i; j >=1 ; j--) { 
               System.out.print(j%2); 
           } 
 
           System.out.println(); 
           } 
 
       } 
 
   } 

 24. Write a program to display following pattern.    

        1 2 3 4 5    

        2 4 6 8 10   

        3 6 9 12 15   

        4 8 12 16 20      

      5 10 15 20 25 ,

import java.util.Scanner; 
 
class Patterns { 
   public static void main(String[] args) { 
       Scanner sc = new Scanner(System.in); 
       System.out.println("How many rows do you want this pattern to have?"); 
       int row = sc.nextInt(); 
       for (int i = 1; i < = 5; i++) { 
           for (int j = 1; j < =5 ; j++) { 
               System.out.print(i*j); 
           } 
 
           System.out.println(); 
           } 
 
       } 
 
   } 

25. Write a program to display following pattern.    

     1    

        1 2    

        1 2 3    

        1 2 3 4    

        1 2 3 4 5    

        1 2 3 4 5 6 7    

        1 2 3 4 5 6    

        1 2 3 4 5    

        1 2 3 4    

        1 2 3    

        1 2    

        1  ,


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

 26. Write a program to display following pattern .   

        1    

        1 2 1    

        1 2 3 2 1    

        1 2 3 4 3 2 1    

        1 2 3 4 5 4 3 2 1    

        1 2 3 4 5 6 5 4 3 2 1    

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

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

 27. Write a program to display following pattern.    

        1 2 3 4 5 6 7    

        1 2 3 4 5 6    

        1 2 3 4 5    

        1 2 3 4    

        1 2 3    

        1 2     

        1     

        1 2    

        1 2 3     

        1 2 3 4     

        1 2 3 4 5    

        1 2 3 4 5 6    

        1 2 3 4 5 6 7  ,

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

28. Write a program to display following pattern.    

        1234567    

          234567    

            34567    

              4567    

                567    

                  67    

                    7    

                  67    

                567    

              4567    

            34567    

          234567    

        1234567  ,

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

 29. Write a program to display following pattern.    

        1    

        2 1    

        3 2 1    

        4 3 2 1    

        5 4 3 2 1     

        6 5 4 3 2 1    

        7 6 5 4 3 2 1  ,

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

 30. Write a program to display following pattern.    

        1  2  3  4  5  6  7     

          2  3  4  5  6  7    

            3  4  5  6  7    

              4  5  6  7    

                5  6  7    

                  6  7    

                    7    

                  6  7    

                5  6  7    

              4  5  6  7    

            3  4  5  6  7    

          2  3  4  5  6  7    

        1  2  3  4  5  6  7  

import java.util.Scanner; 
 
public class Pattern 
{ 
   public static void main(String[] args)  
   { 
       Scanner sc = new Scanner(System.in); 
                  
       System.out.println("How many rows do you want this pattern to have?"); 
         
       int rows = sc.nextInt(); 
                 
       for (int i = 1; i  < = rows; i++)  
       { 
           
           for (int j = 1; j  <  i; j++)  
           { 
               System.out.print(" "); 
           } 
                        for (int j = i; j  < = rows; j++)  
           {  
               System.out.print(j+" ");  
           }  
             
           System.out.println();  
       }  
               for (int i = rows-1; i >= 1; i--)  
       { 
                       for (int j = 1; j  <  i; j++)  
           { 
               System.out.print(" "); 
           } 
           
           for (int j = i; j  < = rows; j++) 
           { 
               System.out.print(j+" "); 
           } 
             
           System.out.println(); 
       } 
            sc.close(); 
   } 
} 
Share This Article
Leave a comment

Leave a Reply

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