Tuesday, September 10, 2019

Print triangle star pattern in Java

Print triangle start pattern in Java


    * 
   * * 
  * * * 
 * * * * 
* * * * * 


Java Code:



public class PatternEx2 {

     public static void main(String[] args) {

          int i, j, k;
          //outer loop for row
          for (i = 1; i <= 5; i++) {
              //inner loop: print space
              for (j = 4; j >= i; j--) {
                   System.out.print(" ");
              }
             
              //inner loop: print * with space
              for (k = 1; k <= i; k++) {
                   System.out.print("* ");
              }
              //Print next line
              System.out.println("");
          }

     }
}


No comments:

Post a Comment

Create a Digital Clock using HTML and JavaScript

Create a Digital Clock using HTML and JavaScript  <! DOCTYPE html> < html > < head > ...

Followers

Search This Blog

Popular Posts