
How to i output this using nested for loops
1
131
13531
1357531
135797531
1357531
13531
131
1

class Pyramid{
public static void main(String[] args){
for(int row = 1; row <= 5; row++){
for(int col = 4; col >= row; col--){
System.out.print(" ");
}
for(int col2 = 1; col2 <= row*2; col2+=2){
System.out.print(col2);
}
for(int col3 = row*2-3; col3 >= 1; col3-=2){
System.out.print(col3);
}
System.out.println();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.