Thursday, January 22, 2015

Java Pyramid Example – Pattern 10


In the program the following star pattern will be printed.



The program is shown below :



package com.skilledmonster.examples.loops;
 
public class PyramidNestedForLoopExample_10 {
 
    public static void main(String[] args) {
 
        int levels = 5 ;
 
        for (int i = 1; i <= levels; i++) {
            for (int s = 1; s < i; s++) {
                              // add spacing
                              System.out.print(" ");
                        }
                        for (int j = levels; j >= i; j--) {
                // display/add star
                System.out.print("* ");
            }
            // add new line
            System.out.println("");
        }
    }
 

}



Output :


No comments:

Post a Comment