File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes If statement now exectutes both if staments but didn't used to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "If statement now exectutes both if staments but didn Watch "If statement now exectutes both if staments but didn New topic
Author

If statement now exectutes both if staments but didn't used to

drew taylor
Greenhorn

Joined: Feb 20, 2006
Posts: 21
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
Sheriff

Joined: Sep 28, 2004
Posts: 18120
    
  39

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 ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
Hi,

Replace this:



By this:



Best of luck ...


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: If statement now exectutes both if staments but didn't used to
 
Similar Threads
Static nad non static Access
Head First GoodDog code error
Two classes defined in the same source file ??
working with book, code compiiles but won't run
Quick question about instance variables