Monday, 15 September 2014

Write a program Java for loop example to print stars in console

Java for loop example to print stars in console

class Stars {
  public static void main(String[] args) {
    int row, numberOfStars;

    for (row = 1; row <= 10; row++) {
      for(numberOfStars = 1; numberOfStars <= row; numberOfStars++) {
        System.out.print("*");
      }
      System.out.println(); // Go to next line
    }
  }
}

O/P:

Java for loop example program output

No comments:

Post a Comment