Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What am I doing wrong?

 
Rich Nelson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic