Q:

Java program to print the following pattern on the console

belongs to collection: Java Pattern programs

0

Algorithm:

  • STEP 1: START
  • STEP 2: SET coe=1, rows= 6.
  • STEP 3: SET i=0. REPEAT STEP 4 to STEP 11 UNTIL i<rows.< li=""></rows.<>
  • STEP 4: SET space = 1. REPEAT STEP 5 and STEP 6 UNTIL space<(rows ?i)
  • STEP 5: PRINT ""
  • STEP 6: ++space
  • STEP 7: SET j=0. REPEAT STEP 8 to STEP 9 UNTIL j<=i .
  • STEP 8: IF(j==0||i==0)
                    SET coe=1
                    ELSE
                    SET coe=coe*(i-j+1) /j
                    PRINT coe
  • STEP 9: SET j = j+1
  • STEP 10: PRINT new line.
  • STEP 11: SET i=i+1
  • STEP 12: END

All Answers

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

Program:

class pattern  
  
   public static void main(String[] args)  
   {  
       int coe=1,rows = 6;  
    for(int i = 0; i < rows; i++) {  
           for(int space = 1; space < rows - i; ++space) {  
               System.out.print("  ");  
           }  
  
           for(int j = 0; j <= i; j++) {  
               if (j == 0 || i == 0)  
                   coe = 1;  
               else  
                   coe = coe * (i - j + 1) / j;  
  
               System.out.printf("%4d", coe);  
           }  
     System.out.println();  
       }  
   }  
  } 

  

Output:

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