Q:

Java program to print the following pattern on the console

belongs to collection: Java Pattern programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

 public class pattern  
{  
    public static void main(String[] args)  
    {   int i ,j;  
        int n = 5;  
            for(i = n; i>0 ; i-- )  
            {  
                 for(j = 1; j<=i ; j++)  
                    {  
                        System.out.print(j);  
                    }  
                         System.out.println("");  
            }  
    }  
}  

Output:

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java program to print the following pattern on the... >>
<< Java program to print the following pattern on the...