Page 251 - CA_Blue( J )_Class9
P. 251

6              {   for(j=1;j<=i;j++)
                   7                  {  if(i%2==0)

                   8                      {  System.out.print("&"); }
                   9                     else

                  10                      {  System.out.print("$"); }
                  11                  }
                  12                  System.out.println();

                  13              }

                  14          }
                  15      }


                 You will get the following output:
























                  Program 6      Write a program to input the number of lines and print the Floyd’s Triangle using for loop.
                                        1
                                        2   3
                                        4   5   6
                                        7   8   9   10

                   1      import java.util.*;
                   2      class for_floyd

                   3      {
                   4          public static void main()

                   5          {
                   6              Scanner sc= new Scanner(System.in);

                   7              int i,j,n,k=1;
                   8              System.out.print("Enter number of lines : ");
                   9              n=sc.nextInt();

                  10              for(i=1;i<=n;i++)


                                                                                                   Nested Loop   249
   246   247   248   249   250   251   252   253   254   255   256