java

Nested while loop in Java language

Nested whileloop in Java language

In this tutorial, we will discuss the Nested while loop in java language.

Nested whileloop

When a whileloop exists inside the body of another whileloop, it is known as nested whileloop in Java.

Flow diagram

flow diagram



Syntex

while(expression)
   {
    statements;

      while(expression)
         {
             statements;
         }
   }

Here we can see, a whileloop is inside the body another whileloop.


Example in nested while loop

Program 1

The program displays square star pattern using nested whileloop

Example


When you execute above code , it produces the folloing result

**********
**********
**********
**********
**********
**********
**********
**********
**********
**********

program 2

The program displays Floyd’s triangle star pattern using nested whileloop.

Program

When you execute above code , it produces the folloing result

*
**
***
****
*****
******
*******
********
*********
**********


Program 3

The program displays multiplication table using nested while loop.

class nestedwhileloop
{
public static void main (String args[])
{
int i=1, j=1;
System.out.println(“Tables”);
while(i<=2)
{
while(j<=12)
{
System.out.println(i+”*”+j+”=”+(i*j));
j++;
}
i++;
System.out.println(“”);
j=1;

}
}

}

When you execute above code , it produces the folloing result.

Program

Related Links

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.