• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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

 
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?
 
author
Posts: 23834
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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 ]
 
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Replace this:



By this:



Best of luck ...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!