• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why this is not equal

 
Ranch Hand
Posts: 202
Android PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could someone please explain me why following code always return false.

 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find out by printing the value of x
 
ibrahim yener
Ranch Hand
Posts: 202
Android PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The output is equal



The question is definitely an Integer value
but i am not sure Integer.parseInt (answer); is really converting into Integer
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure, but try printing a character before your output...something like



it is possible there is whitespace that you are just not seeing.
 
ibrahim yener
Ranch Hand
Posts: 202
Android PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i changed my code into textField.getText().trim(); and still same.
 
Marshal
Posts: 79242
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As well as that, please explain how that code compiles in the first place.
 
ibrahim yener
Ranch Hand
Posts: 202
Android PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Campbell Ritchie
Here is entire Code.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you run that, you should see a NumberFormatException happen in line 95, because answer is "" (empty string).

In line 19, you are initializing answer to "" but nowhere else in your code you are assigning the value entered in a text field to answer.
 
ibrahim yener
Ranch Hand
Posts: 202
Android PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Jesper
Sorry it is my fault, i forgot rename it at line 70.

cevap = textField.getText ().trim();

should be

answer = textField.getText ().trim();
 
Campbell Ritchie
Marshal
Posts: 79242
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jesper is right and I was mistaken; it will fail at run‑time with that Exception, not at compile‑time.
 
ibrahim yener
Ranch Hand
Posts: 202
Android PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay guys
First of all, i want to thank to whom tried to help me.

Finally i found problem and fixed it. I am going to describe problem and provide solution and hopes this helps somebody else.

Problem caused by line #49 (calling setComponents method setComponents();) because whenever user hit the answer button
program generates new random number but user's entered value still keeps old one so checkAnswer(); method always try to compare new code and old code therefor it always return false.


Solution was simple: Removed setComponents(); method call at line #49 and place it bottom of checkAnswer(); method.
When program checks user's answer than call setComponents(); method.

Hope this help someone else too.

Appreciate for help.

Regards
 
reply
    Bookmark Topic Watch Topic
  • New Topic