Q:

Java program to print the following pattern on the console

belongs to collection: Java Pattern programs

0

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

Algorithm:

  • STEP 1: START
  • STEP 2: SET n=5.
  • STEP 3: SET i=0. REPEAT STEP 4 to STEP 8 UNTIL i<=n.
  • STEP 4: SET j=0.REPEAT STEP 5 to STEP 6 UNTIL j<i.< li=""></i.<>
  • STEP 5: PRINT j+1
  • STEP 6: SET j=j+1
  • STEP 7: PRINT new line.
  • STEP 8: SET i=i+1.
  • STEP 9: END

All Answers

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

Program:

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

Output:

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

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...