aspose file tools*
The moose likes Beginning Java and the fly likes Switch error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Switch error" Watch "Switch error" New topic
Author

Switch error

ed spithaler
Greenhorn

Joined: Feb 29, 2012
Posts: 9
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

Joined: Mar 17, 2011
Posts: 8244
    
  23

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18997
    
  40

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.







Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Shamsudeen Akanbi
Ranch Hand

Joined: Dec 24, 2010
Posts: 72
Hey man! looks like you've not actually initialised the variable "d".
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39869
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Switch error