Java for loop print shape using nested for loop 3

Question

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


**********// w w w .  ja va 2 s .c o m
 *********
  ********
   *******
    ******
     *****
      ****
       ***
        **
         *
          


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



PreviousNext

Related