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 then else statement

 
Ola Olusegun
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am beginning to enjoy writing noob codes in java, but i am kinda lost here. please check the code below and tell me why the 2nd else if part is not displaying hurray you are welcome. it's always going to the else part. i feel i have met the conditions for it to display the hurray part.please advise me on what to do.

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With a value of 48 for toyin, do you really think either of the if conditions in lines 12 or 15 should be satisfied?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just ran that code, and I got the output "hurray you are welcome". Are you sure the code you are running is the code you just posted?

A couple of things about your if statements, though:

- (toyin <= 18 && toyin == 18) is just the same as (toyin == 18). If the second part is true the first must be.

- (toyin == 18 || toyin == 19) in this context is that same as (toyin == 19). If toyin is 18 then the execution would never reach that line because the first if condition would be true.
 
Ola Olusegun
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Mathew Brown, If it returned hurray after you ran it, then i must have been right, but the netbeans ide is not showing that . Why is my IDE returning the else statements below ?
 
Ola Olusegun
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
When i used notepad++ to write the same code, I compiled it in command prompt and got the following error message.I wonder why it is running in Net beans . The error message. Exception in thread "main" java.lang.NoClassDefFoundError ifThenElse <wrong name: ifThenElse/ifThenElse> .It had some package extensions below.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding your Notepad++ question, I saw your other post first and answered it there, please do not ask the same question in multiple posts. I'll leave this post open because I think you are still asking questions related to your original question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic