Monday 28 May 2018

Java Program to print Pyramid of stars using nested for loops



Pyramid Example:-

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

Sample Program:-


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

Output:-


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

Enjoy Programming.

No comments:

Post a Comment