Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Hollow pyramid star pattern in java

class hollowPyramid {
  public static void main(String[] args) {
    // size of the pyramid
    int size = 5;
    for (int  i = 0; i < size; i++) {
      // print spaces
      for (int j = 0; j < size - i - 1; j++) {
        System.out.print(" ");
      }
      // print stars
      for (int k = 0; k < 2 * i + 1; k++) {
        if (i == 0 || i == size - 1) {
          System.out.print("*");
        }
        else {
          if (k == 0 || k == 2 * i) {
            System.out.print("*");
          }
          else {
            System.out.print(" ");
          }
        }
      }
      System.out.println();
    }
  }
}
Source by www.tutorialstonight.com #
 
PREVIOUS NEXT
Tagged: #Hollow #pyramid #star #pattern #java
ADD COMMENT
Topic
Name
6+8 =