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

 
drew taylor
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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?
 
Henry Wong
author
Marshal
Pie
Posts: 21385
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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 ]
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Replace this:



By this:



Best of luck ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic