Page 181 - computer science (868) class 11
P. 181

22                              System.out.print("*");
                  23                          }

                  24                          System.out.println("");
                  25                      }

                  26                      break;
                  27                  case 2:

                  28                      System.out.println("Enter the number of rows: ");
                  29                      rows = sc.nextInt();
                  30                      for (i= 0; i<= rows-1; i++)    {

                  31                          for (j=0; j<=i; j++)    {

                  32                              System.out.print(" ");
                  33                          }
                  34                          for (k=0; k<=rows-1-i; k++)

                  35                          {
                  36                              System.out.print("*" + " ");

                  37                          }
                  38                          System.out.println();

                  39                      }
                  40                      break;

                  41                  default: System.out.println("Wrong Choice");
                  42              }

                  43          }
                  44      }


                 The output of the preceding program is as follows:
                 1.  Pattern 1
                 2.  Pattern 2
                 Enter your choice
                 1
                 Enter number of rows:
                 5
                            *
                           **
                         ***
                       ****
                     *****









                                                                                                                       179
                                                                                                 Statements and Scope  179
   176   177   178   179   180   181   182   183   184   185   186