For loop output when scaling figure in java
I have been unable to get my for loop to run right number of times with my
"figure" when scaling. The LINES constant here is the scaling "number".
The problem i am facing lies here i think:
for(int k = 0; k < LINES; k++){
System.out.print("*******");
}
It is supposed to make a line of * at the bottom.
This is my whole code which produces a stairs figure of some kind
public class PP5 {
public static int j;
public static final int LINES = 5;
public static void main(String[] args) {
for(j = 0 ; j < LINES; j++){
fSpaces();
System.out.print(" o *******");
bSpaces();
System.out.println("*");
fSpaces();
System.out.print(" /|\\ *");
bbSpaces();
System.out.println("*");
fSpaces();
System.out.print(" / \\ *");
bbSpaces();
System.out.println("*");
}
for(int k = 0; k < LINES; k++){
System.out.print("*******");
}
}
public static void fSpaces(){
for(int i = (LINES-1); i > j; i--){
System.out.print(" ");
}
}
public static void bSpaces(){
for(int i = 0; i < j; i++){
System.out.print(" ");
}
}
public static void bbSpaces(){
for(int i = 0; i < j+1; i++){
System.out.print(" ");
}
}
}
Any optimizations is highly appreciated. Thanks
No comments:
Post a Comment