[SOLVED] Understanding if else statements
I am having a hard time understanding how to evaluate if else statements. I am a total newbie to Java but I am really trying hard to learn. I am trying to figure out how the following works:
Based on the code below, what is the value of y if x = 5?
int x, y;
if(x > 5)
y= 1;
else if (x < 5){
if(x < 3)
y = 2;
else
y= 3;
}
else
y = 4;
I am guessing that since x is = to 5 then y is = to 3 because of the closing brace but I am not really sure how this works. Can anyone walk me through how the logic flows in this code? I would really appreciate it. Also what if the value of x started out to be a different value like 6 or 3 and what would x be if y was 2?
I am guessing that if x was 6 y is 1 and if x is 3 y would be 4. Finally, if y were found to be 2 x could be 2 or 1. I am I way off base here or what? I appreciate any help you all can give me to understand this stuff. :)