Java for loop print shape using nested for loop 4

Question

We would like to output the following shape using nested for loop.

pattern:/*from www  .j  av a 2 s . c  om*/
         *
        **
       ***
      ****
     *****
    ******
   *******
  ********
 *********
**********


public class Main {
  public static void main(String[] args) {
    for (int i = 1; i <= 10; i++) {
      // blank spaces
      for (int j = 10 - i; j > 0; j--) {
        System.out.print(' ');
      }
      for (int k = 0; k < i; k++) {
        System.out.print('*');
      }
      System.out.println();
    }

  }
}



PreviousNext

Related