DEV Community

Preethi Nandhagopal
Preethi Nandhagopal

Posted on

Nested while loop programs

1)Print pattern program like
11111
11111
11111

public class TwentyTwo{
public static void main (String[] args){
int row=1;
while(row<=3){
int col=1;
while(col<=5){
System.out.print(1);
col++;
}
row++;
System.out.println();
}
}
}

2)Print pattern program on
11111
22222
33333

public class TwentyThree{
public static void main (String[] args){
int row=1;
while(row<=3){
int col=1;
while(col<=5){
System.out.print(row);
col++;
}
System.out.println();
row++;
}
}
}

3)Print pattern program on
1
11
111

public class TwentyFour{
public static void main (String[] args){
int row=1;
while(row<=3){
int col=1;
while(col<=row){
System.out.print(1);
col++;
}
System.out.println();
row++;
}
}
}

4)Print pattern program on
*
**


public class TwentyFive{
public static void main (String[] args){
int row=1;
while(row<=3){
int col=1;
while(col<=row){
System.out.print('*');
col++;
}
System.out.println();
row++;
}
}
}

5)Print pattern program on
1
22
333

public class TwentySix{
public static void main (String[] args){
int row=1;
while(row<=3){
int col=1;
while(col<=row){
System.out.print(row);
col++;
}
System.out.println();
row++;
}
}
}

6)Print pattern program on
1
12
123

public class TwentySeven{
public static void main (String[] args){
int row=1;
while(row<=3){
int col=1;
while(col<=row){
System.out.print(col);
col++;
}
System.out.println();
row++;
}
}
}

7)Print pattern program on
A
BB
CCC
DDDD

public class TwentyEight{
public static void main (String[] args){
char row='A';
while(row<='D'){
int col='A';
while(col<=row){
System.out.print(row);
col++;
}
System.out.println();
row++;
}
}
}

8)Print pattern program on




**
*
public class TwentyNine{
public static void main (String[] args){
int row=1;
while(row<=5){
int col=5;
while(col>=row){
System.out.print('*');
col--;
}
System.out.println();
row++;
}
}
}

Top comments (0)