Some Java Pattern Programs to practice(part 1)

Codynn
7 Min Read
Contents: Click for quick access
  1.Write a program to display following.        1 1 1 1               2 2 2 2           3 3 3 3           4 4 4 4   ,  2. Write a program to display following pattern.            1 2 3 4 5            1 2 3 4 5           1 2 3 4 5                 1 2 3 4 5 3. Write a program to display following pattern.            5 5 5 5 5            4 4 4 4 4           3 3 3 3 3           2 2 2 2 2            1 1 1 1 1 ,4. Write a program to display following pattern.            5 4 3 2 1            5 4 3 2 1           5 4 3 2 1                  5 4 3 2 1   , 5. Write a program to display following pattern.            1            1 2            1 2 3            1 2 3 4           1 2 3 4 5 ,6. Write a program to display following pattern.            1 2 3 4 5           1 2 3 4           1 2 3            1 2            1 ,7. Write a program to display following pattern.            5 4 3 2 1            4 3 2 1           3 2 1           2 1            1  ,8. Write a program to display following pattern.            1            2 1           3 2 1            4 3 2 1           5 4 3 2 1 ,9. Write a program to display following pattern.            5 5 5 5 5            4 4 4 4           3 3 3           2 2           1 ,10.  Write a program to display following pattern .           1            2 2           3 3 3            4 4 4 4           5 5 5 5 5 ,

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

 

 1.Write a program to display following.

        1 1 1 1       

        2 2 2 2   

        3 3 3 3   

        4 4 4 4   ,

import java.util.Scanner; 
 
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<  =rows; j++){ 
               System.out.print(i+" "); 
           } 
           System.out.println(); 
       } 
 
       } 
} 

  

2. Write a program to display following pattern.    

        1 2 3 4 5    

        1 2 3 4 5   

        1 2 3 4 5         

        1 2 3 4 5

import java.util.Scanner; 
 
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< =rows; j++){ 
               System.out.print(j+" "); 
           } 
           System.out.println(); 
       } 
 
       } 
}  

 3. Write a program to display following pattern.    

        5 5 5 5 5    

        4 4 4 4 4   

        3 3 3 3 3   

        2 2 2 2 2    

        1 1 1 1 1 ,

import java.util.Scanner; 
 
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=rows; j>=1; j--){ 
               System.out.print(i+" "); 
           } 
           System.out.println(); 
       } 
 
       } 
}  

4. Write a program to display following pattern.    

        5 4 3 2 1    

        5 4 3 2 1   

        5 4 3 2 1          

        5 4 3 2 1   ,

 import java.util.Scanner; 
 
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=rows; j>=1; j--){ 
               System.out.print(i+" "); 
           } 
           System.out.println(); 
       } 
 
       } 
}   

 5. Write a program to display following pattern.    

        1    

        1 2    

        1 2 3    

        1 2 3 4   

        1 2 3 4 5 ,

 
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(); 
       }          
       sc.close(); 
   } 
} 
 

6. Write a program to display following pattern.    

        1 2 3 4 5   

        1 2 3 4   

        1 2 3    

        1 2    

        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 = row; i >= 1; i--) { 
           for (int j = 1; j < = i; j++) { 
               System.out.print(j+" "); 
           } 
           System.out.println(); 
       } 
 
 
   } 
} 

7. Write a program to display following pattern.    

        5 4 3 2 1    

        4 3 2 1   

        3 2 1   

        2 1    

        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 = row; i >= 1; i--) { 
           for (int j = i; j >= 1; j--) { 
               System.out.print(j+" "); 
           } 
           System.out.println(); 
       } 
 
 
   } 
} 

8. Write a program to display following pattern.    

        1    

        2 1   

        3 2 1    

        4 3 2 1   

        5 4 3 2 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 < = row; i++) { 
           for (int j = i; j >= 1; j--) { 
               System.out.print(j+" "); 
           } 
           System.out.println(); 
       } 
 
 
   } 
} 

9. Write a program to display following pattern.    

        5 5 5 5 5    

        4 4 4 4   

        3 3 3   

        2 2   

        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 = row; i >= 1; i--) { 
           for (int j = 1; j < = i; j++) { 
               System.out.print(i+" "); 
           } 
           System.out.println(); 
       } 
 
 
   } 
} 

10.  Write a program to display following pattern .   

        1    

        2 2   

        3 3 3    

        4 4 4 4   

        5 5 5 5 5 ,

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(i+" "); 
           } 
             
           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 *