• 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

Switch error

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
/**




*/
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.





 
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey man! looks like you've not actually initialised the variable "d".
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic