Thursday, 5 December 2013

Unknown

Pyramid of stars using nested for loops

/*
 Java Pyramid 1 Example
 This Java Pyramid example shows how to generate pyramid or triangle
 like given below using for loop.
 *
 **
 ***
 ****
 *****
 */

public class JavaPyramid1 {

    public static void main(String[] args) {
        for (int i = 1; i <= 5; i++) {
            for (int j = 0; j < i; j++) {
                System.out.print("*");
            }
//generate a new line
            System.out.println("");
        }
    }
}
/*
Output of the above program would be
*
**
***
****
*****
*/

Unknown

About Blog No Baap -

Since 2016 BlogNoBaap has been bringing you the very best in all types of web resources. Posted daily, and delivered straight to your inbox each morning.

Subscribe to this Blog via Email :