Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Switch error  RSS feed

 
ed spithaler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every time I enter A to test the switch it prints out 9999.99. I am trying to use charAt(0) which should match case A, but it does not work. Anybody have any ideas? Thanks.

import java.util.Scanner;
/**




*/
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ed spithaler wrote:Every time I enter A to test the switch it prints out 9999.99. I am trying to use charAt(0) which should match case A, but it does not work. Anybody have any ideas? Thanks.

Please UseCodeTags (←click), but off the top of my head I would add a print statement right before the switch to see what you're actually switching on.

Winston
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Considering that there is nothing related to 9999.99 in the switch statement, and there are 9999.99 in the if-else statements that follows, I think it is safe to say that you are looking in the wrong place for the issue.

Henry


ed spithaler wrote:Every time I enter A to test the switch it prints out 9999.99. I am trying to use charAt(0) which should match case A, but it does not work. Anybody have any ideas? Thanks.





 
Shamsudeen Akanbi
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey man! looks like you've not actually initialised the variable "d".
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shamsudeen Akanbi wrote:Hey man! looks like you've not actually initialised the variable "d".
Yes, he has. By making the mistake of using d as a field rather than a local variable, he has initialised it (implicltly) to \0. So it does not == 'R'.
Try changing the value d to a local variable in that method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!