I am making a diamond using ASCII art. Yes, I know the code is beyond sloppy. Anyways, the last part is not running inside of an else block, leaving the diamond not finished.
Full code:
http://pastebin.com/14HnZADe
Current output:
http://pastebin.com/YTqKrRQe
The for loop:
for(int i = 1; i<=size; i++) {
for(int j=1; j<=size; j++) {
if(j<i) {
System.out.print(" ");
}
else if(j==i || j>i) {
System.out.print("*");
} else {//this block is not executing, and I do not know why.
for(int ki = 1; ki<=size; ki++) { // how do I fix it?
for(int n = size; n>=1; n--) {
if(j>=i) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
System.out.println();
}
One of your conditions has to be met before it gets to the else
block:
if(j<i) {
System.out.print(" ");
}
else if(j==i || j>i) {
j
is either less than i
or greater than i
or equal to i
. You have specified all possible conditions therefore the else
will never execute...