DEV Community

Preethi Nandhagopal
Preethi Nandhagopal

Posted on

Nested for loop program:

1)To print the pattern program on alphabet:
A
A B
A B C
A B C D

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

2)To print the inverted star pattern:




**
*

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

Top comments (0)