jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes What am I doing wrong? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What am I doing wrong?" Watch "What am I doing wrong?" New topic
Author

What am I doing wrong?

Rich Nelson
Greenhorn

Joined: Sep 22, 2007
Posts: 15
Hello,

For my homework, I was asked to write a simple math test program with two levels of difficulty: easy and hard.



The problem is, when I run the program and choose a difficulty level, it acts as if I spelled the difficulty wrong. It would probably be best if someone could run this program to see what exactly happens. I've been trying to figure out what I'm doing wrong for hours now; everything seems to basic and easy, I can't imagine what I'm doing wrong.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2169
    
  47
The problem is your test for the level entered by the user. == does not test that the words are the same, it tests that the object references are the same ie they reference the same object. When testing that 2 objects are equal in value to each other you should always use the equals() method. Although in this case it might be better to use the equalsIgnoreCase() method which is a special equals test provided by the String class to allow an equals test to be done regardless of the capitalisation of the strings.
Rich Nelson
Greenhorn

Joined: Sep 22, 2007
Posts: 15
Thank you very much!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: What am I doing wrong?
 
Similar Threads
Do while error, I'm going crazy
Making a simple blackjack game
Simple Problem (if else statments)
math program help..
How close am I in getting this program right?