Contents: Click for quick access
41. Write a program to display following pattern.                5                4 5               3 4 5              2 3 4 5             1 2 3 4 5  , 42. Write a program to display following 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  , 43. Write a program to display following 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   ,44. Write a program to display following pattern.           1             2 4             3 6 9             4 8 12 16             5 10 15             6 12             7  , 45. Write a program to display following 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  ,46. Write a program to display following 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  , 47. Write a program to display following 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  ,48. Write a program to display following 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  ,49. Write a program to display following pattern.            1        1            12      21            123    321            1234  4321            1234554321  ,
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
41. Write a program to display following pattern.
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5 ,
42. Write a program to display following 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 ,
import java.util.Scanner; 
 
public class Pattern{ 
   public static void main(String[] args) 
   { 
        
       Scanner scanner = new Scanner(System.in); 
 
       System.out.println("How many rows do you want this pattern to have?"); 
 
       int rows = scanner.nextInt(); 
               
       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(); 
       } 
   } 
} 
43. Write a program to display following 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 ,
import java.util.Scanner; 
 
public class Pattern 
{ 
   public static void main(String[] args) 
   { 
     Scanner scanner = new Scanner(System.in); 
 
        
       System.out.println("How many rows do you want this pattern to have?"); 
 
       int rows = scanner.nextInt(); 
       
        
       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(); 
       } 
   } 
} 
44. Write a program to display following pattern.
1
2 4
3 6 9
4 8 12 16
5 10 15
6 12
7 ,
import java.util.Scanner; 
 
public class Pattern 
{ 
   public static void main(String[] args) 
   { 
       Scanner scanner = new Scanner(System.in); 
 System.out.println("How many rows do you want this pattern to have?"); 
 
       int rows = scanner.nextInt(); 
               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++; 
       } 
   } 
} 
45. Write a program to display following 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 ,
import java.util.Scanner; 
 
public class Pattern 
{ 
   public static void main(String[] args) 
   { 
     Scanner scanner = new Scanner(System.in); 
 
       System.out.println("How many rows do you want this pattern to have?"); 
 
       int rows = scanner.nextInt(); 
              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(" "); 
       } 
   } 
} 
46. Write a program to display following 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 ,
import java.util.Scanner; 
 
public class Pattern{ 
   public static void main(String[] args) 
   { 
        
       Scanner scanner = new Scanner(System.in); 
 
       System.out.println("How many rows do you want this pattern to have?"); 
 
       int rows = scanner.nextInt(); 
        
       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(); 
       } 
   } 
} 
47. Write a program to display following 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 ,
import java.util.Scanner; 
 
public class Pattern 
{ 
   public static void main(String[] args) 
   { 
      Scanner scanner = new Scanner(System.in); 
       System.out.println("How many rows do you want this pattern to have?"); 
 
       int rows = scanner.nextInt(); 
 
       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(); 
   } 
} 
 
48. Write a program to display following 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 ,
import java.util.Scanner; 
 
public class Pattern 
{ 
   public static void main(String[] args) 
   { 
        Scanner scanner = new Scanner(System.in); 
 
       System.out.println("How many rows do you want this pattern to have?"); 
 
       int rows = scanner.nextInt(); 
 
       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(); 
   } 
} 
 
49. Write a program to display following pattern.
1 1
12 21
123 321
1234 4321
1234554321 ,
import java.util.Scanner; 
 
public class Pattern 
{ 
   public static void main(String[] args) 
   { 
     Scanner scanner = new Scanner(System.in); 
       System.out.println("How many rows do you want this pattern to have?"); 
 
       int rows = scanner.nextInt(); 
        
       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(); 
   } 
}