This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes If then else statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "If then else statement " Watch "If then else statement " New topic

If then else statement

Ola Olusegun

Joined: Jun 13, 2013
Posts: 15
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

Joined: Mar 22, 2005
Posts: 41127
With a value of 48 for toyin, do you really think either of the if conditions in lines 12 or 15 should be satisfied?

Ping & DNS - my free Android networking tools app
Matthew Brown

Joined: Apr 06, 2010
Posts: 4343

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

Joined: Jun 13, 2013
Posts: 15
@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

Joined: Jun 13, 2013
Posts: 15
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

Joined: May 14, 2008
Posts: 5812

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.

JBoss In Action
wood burning stoves
subject: If then else statement
Similar Threads
What does it mean by final method arguments or final local variables in a instance method ?
Spotting errors
Unable to Access mysql database through JNDI.
Library System