Why does this java code return no output? -
This is a question on quiz. The question asks is whether the output is given when this code is run. I do not understand why anybody is not producing anything, can anyone explain? My understanding of if / else is that if the statement fails and the statement runs, why does the other statement not run?
Code:
int age = 10; Four registered = 'n'; If (age and gt; = 18) {if (registered == 'Y') {System.out.println ("you can vote!"); } else {System.out.println ("You are not old enough");}}
Because this real code (correctly indented): if (age> = 18) {if (registered ==) 'y') {System.out.println ("You can vote!"); } else {System.out.println ("You are not old enough"); }} age is less than 18 , so the outermost if -statement is executed nothing. (I think this is a horrible quiz question, to be honest. This is nothing more than a trick with a bracket - it does not actually test your knowledge of Java.) < / p>
Comments
Post a Comment