Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Nested For Loop means we will write more then one for loop using nested sequence.it has collection of inner for loop and outer for loop,
outer for loop will execute once but inner for loop will continuously executed.
for(init;condition;increment)
{
    for(init;condition;increment)



{
         System.out.print("statement");
    }
    System.out.println();

}

WAP to print following statement?

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
............................................................................................

A a B b C
A a B b
A a B
A a
A
..................................................................................................


Solution of This Program:


class Pattern
{
   public static void main(String args[])
   {
     for(int i=1;i<=5;i++)
     {
         int asc=65;
         for(int j=1;j<=6-i;j++)
          {
              if(j%2!=0)
              System.out.print((char)asc+" ");
              else
              {
              System.out.print((char)(asc+32)+" ");
              asc++;
              } 

          }
         System.out.println();   
         

     }       
   }


}

............................................................................................................................................

1 2 3 4 5
5 4 3 2
1 2 3
5 4
1
.......................................................................


class Pattern
{
   public static void main(String args[])
   {
     for(int i=1;i<=5;i++)
     {
       
         for(int j=1;j<=6-i;j++)
          {
              if(i%2!=0)
              System.out.print(j+" ");
              else
              {
              System.out.print((6-j)+" ");
           
              } 

          }
         System.out.println();   
         

     }       
   }


}

.....................................................................................................................................................

ASSIGNMENT:-

1 0 0 1 0
1 0 0 1
1 0 0
1 0
1
.................................................................................

A B C D E
    B C D E
        C D E
            D E
                E
.........................................................................................

             8
     8      8     8
8   8     8      8    8
     8     8      8
            8

................................................................................................









Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post