Home » Java program to print the following pattern on the console 6

Java program to print the following pattern on the console 6

by Online Tutorials Library

Java program to print the following pattern on the console

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Algorithm:

  • STEP 1: START
  • STEP 2: DEFINE i, j.
  • STEP 3: SET n=5.
  • STEP 4: SET i=n. REPEAT STEP 5 to STEP 7 UNTIL i>0.
  • STEP 5: SET j=1. REPEAT STEP 6 UNTIL j<=i.
  • STEP 6: PRINT j and SET j=j+1.
  • STEP 7: PRINT “” and SET i=i-1.
  • STEP 8: END

Program:

Output:

1 2 3 4 5  1 2 3 4  1 2 3  1 2  1  
Next TopicJava Programs

You may also like