Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

if statement question from JQ+

 
Jon Rosenbaum
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is the code snippet from one of the questions:

The thing I don't understand is how this compiles. I'm confused because there is a semi-colon at the end of the second if, which to me would make the else be its own statement that is not connected to an if. I'm obviously missing something since it does compile, so I was wondering if someone could please clear the cobwebs for me.
Thanks.
Jon
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The semi-colon is not at the end of the if statement. It is at the end of the println statement. In Java, every statement must end with a semi-colon.
Also, the else should line up with the second if.
------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic