I am building a program to make a pyramid as such.
1
1 2 1
1 2 4 2 1
Etc. For 8 rows.
public class PrintingNumbers {
public static void main (String [] args) {
int k = 1;
for (int i = 1; i <= 8; i++) {
for (int j = 1; j <= 8 - i; j++){
System.out.printf("%5s", "");
}
for (k = 1; k < i*2;) {
System.out.printf("%5d", k);
k=k*2;
}
for (k=k/2; k >= 2;){
k=k/2;
System.out.printf("%5d", k);
}
System.out.println();
}
}
}
Currently this is my code. It works until the 4th iteration where the continuation statement for my loop becomes k = 8 and 8 !> 8. I need help trying to devise a better continuation statement for my loop so it stays with the format. Any help with be appreciated.