Page 301 - CA_Blue( J )_Class9
P. 301

7              int i, j, ch, k=1, c=64;                     //Declaration of variable
                   8              System.out.println(" MENU ");

                   9              System.out.println("Enter 1 for Floyd's triangle");
                  10              System.out.println("Enter 2 for pattern");

                  11              System.out.print("Enter your choice: ");
                  12              ch = sc.nextInt();                           //Accepting choice
                  13               switch (ch)                                 //Switch block

                  14      {

                  15                  case 1:
                  16                    for (i = 1; i <= 5; i++)               //Printing of Floyd's triangle
                  17      {

                  18                      for (j = 1; j <= i; j++)
                  19      {

                  20                          System.out.print(k + "\t");
                  21                               k++;

                  22                      }
                  23                      System.out.println();

                  24                  }
                  25                  break;                              //Used to exit from case 1

                  26                      case 2:
                  27

                  28                  for (i = 1; i <= 4; i++)   //Printing of pattern 2
                  29       {

                  30                      for (j = 1; j <= i; j++)
                  31      {

                  32                          System.out.print((char)(c+j) + "\t");
                  33                      }

                  34                      System.out.println();
                  35                  }

                  36                  break;
                  37                    default:
                  38                  System.out.println("Wrong Choice");

                  39              }

                  40          }}



                                                                                             Internal Assessment  299
   296   297   298   299   300   301   302   303   304   305   306