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

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.