c g c g - 29 days ago 19
Java Question

Why is this code block not running?

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();
}

Answer

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...