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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -