Java for loop output patterns

Question

We would like to write a program that uses loops to display the following pattern:

What is the output of the following code?

*
**
***//w  w w .  j a v  a2 s  . co m
****
*****
*
**
***
****
*****
*
**
***
****
*****


public class Main {

  public static void main(String[] args) {

    for (int copy = 0; copy < 3; copy++) {
      for (int row = 0; row < 5; row++) {
        for (int column = 0; column <= row; column++) {
          System.out.print("*");
        }
        System.out.println();
      }
    }

  }
}



PreviousNext

Related