• 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 statement now exectutes both if staments but didn't used to

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Please help me if you can.

I'm using netbeans, I have a Dog class with a bark() method which contains an If/Else Statement:

void bark() {
if (size > 60) {
System.out.println("Woof! Woof!");
} // If

if (size > 14) {
System.out.println("Ruff! Ruff!");
} // If

else {
System.out.println("Yip! Yip!");
} }

When I call this method from the Dog class with a new Dog object (after I have initialised it with a value of 64, the If statements execute If size > 60 AND if size > 14 and it didn't before! Why is this? It used to just execute the top If statement.

The only thing I can think of is that I was trying to define set CLASSPATH on the command prompt the other day (to no success even though it was pointing right to the folder for javac etc) but I don't think this would cause an If statement to execute like this?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If statements execute If size > 60 AND if size > 14 and it didn't before! Why is this?



Just as a guess -- did you happen to delete the "else" keyword that was betweeen the two IF statements? That is the only thing that I could think of that could make "it didn't before".

Henry
[ October 05, 2007: Message edited by: Henry Wong ]
 
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Replace this:



By this:



Best of luck ...
 
Don't play dumb with me! But you can try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic