Thursday, January 22, 2015

Java Pyramid Example – Pattern 5


In the program the following star pattern will be printed.



The program is shown below :

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


Output :


No comments:

Post a Comment