• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

If then else statement

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic