my dog learned polymorphism*
The moose likes Beginning Java and the fly likes switch statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "switch statement" Watch "switch statement" New topic
Author

switch statement

Keith Warzak
Greenhorn

Joined: Mar 19, 2001
Posts: 2
I am trying to read in from a text file with a readline buffer that reads in the first string. The first string is then used in the switch statement, allowing it to assign the following number of incoming lines from the text file to certain variables and then be printed to the command line. I believe my problem is that I am trying to passed a string value into my switch statement, but I think I need this same value in my "if" statement to determine if it is at the end of the file.
Here is my code:
----------------------------------------------------------------

added UBB CODE tags to preserve indentation
[This message has been edited by Frank Carver (edited March 26, 2001).]
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
There are a few problems with this. First is that you have put quotes around 'type' in the switch, so it is not referencing the string variable, but a constant char variable instead. If what you want is to switch on the first character of the line, then use the following:
switch(type.charAt(0))
insead of
switch('type')
If this is not what you want, then please explain further what behaviour you require.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Keith Warzak
Greenhorn

Joined: Mar 19, 2001
Posts: 2
Thank you
 
wood burning stoves
 
subject: switch statement