Nested Loop – Logical Pattern

We already see nested loop in our last blog, now we will work on logical pattern example.

*

12

***

1234

*****

 

Program on – Logical nested loop

class LoopEx5

{

            void method1()

            {

                        int i,j;

                        for(i=1;i<=5;i++)    // Loop

                        {

                                    for(j=1;j<=i;j++)

                                    {

                                                if(i%2==0)

                                                System.out.print(j);

                                                else

System.out.print(“*”);

                                    }

                                    System.out.println();

}

}

}

class loop5

{

          public static void main(String args[])

          {

                   LoopEx5 obj = new LoopEx5();

                    obj.method1();

}

}

Output:

*

12

***

1234

*****

 

You can see nested loops program on YouTube

 

 

If you have problem on this blog, you can directly comment on it. This tutorial will help you understand the concepts of java loop programs.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

182total visits,1visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

EmailEmail
PrintPrint