Pattern Program #2
Program to display the following number pattern on screen.
Pattern :-
12345 1234 123 12 1 12 123 1234 12345
Algorithm and Program given below :-
Algorithm :-
Program is divided into two parts
1. Make loop in descending order to print pattern till 1 i.e.
12345 1234 123 12 1
2. Then make loop in ascending order to print the remaining elements i.e.
12
123
1234
12345
3. Now Compile and run the program.
Program :-
class Pattern { public static void main(String args[]) { int i,j; for(i=5;i>=1;i--) // Decrement Loop to print pattern in descending order { for(j=1;j<=i;j++) { System.out.print(j); } System.out.println(); } for(i=2;i<=5;i++) // increment loop to print the pattern then in ascending order { for(j=1;j<=i;j++) { System.out.print(j); } System.out.println(); } } // end of main method } // end of class
Note : The program is written in the easiest way possible so try understand it. If you face any problem in understanding this program than feel free to contact/comment.
All the Best :)
Keep Learning :)
Comentarios