• Post Reply Bookmark Topic Watch Topic
  • New Topic

Whats wrong with this code?  RSS feed

 
Lucas Mulherin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


So, this is my first day learning Java.. or any coding at all. So yeah, I'm a noob.
But I got this code going...
and it asks;
"5+5:"
And when I enter "10"
it says "You were wrong! Try again!"
but I told it to say "You are correct!" if you enter 10.
at least I think I have it set up correctly to say that.

Could some one let me know why this isnt working?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


That line is asking if the String "input" is equal to the String "10". This is always false, of course. And note that the String literal "input" has nothing whatsoever to do with your input variable.

You want to test whether your int variable input has the int value 10.
 
Lucas Mulherin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I go about "testing" it?
sorry if I have any misunderstandings, all of this stuff is hard to wrap my head around at the moment
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lucas Mulherin wrote:How would I go about "testing" it?


You want



sorry if I have any misunderstandings, all of this stuff is hard to wrap my head around at the moment


No need to apologize. We all have to start somewhere.

Oddly enough, you made the exact opposite mistake from what most beginners do. Usually people start off learning == and then try to use it for objects (usually Strings, like if (name == "Joe") ) and it doesn't work the way the expect, and we have to explain to them to use equals() for comparing objects' states (contents). Congratulations on being original!
 
Lucas Mulherin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yay! originality! Haha. Well I tried something with the '==' earlier... maybe I just didn't do it right!
Thanks for the help!
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!