aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes switch case problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "switch case problem" Watch "switch case problem" New topic
Author

switch case problem

deepesh mathur
Ranch Hand

Joined: Aug 13, 2007
Posts: 39
i just want to ask weather boolean/string can be used for a switch case loop b'cause it's not specified in k&b
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

Why don't you give it a try first whether it's possible? That way you will learn more


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
sara adrem
Greenhorn

Joined: Jul 26, 2007
Posts: 15
boolean and String can't be used as argument to switch.

//A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types (discussed in Classes and Inheritance) and a few special classes that "wrap" certain primitive types: Character, Byte, Short, and Integer (discussed in Simple Data Objects ).//

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html


<a href="http://eathumblepie.blogspot.com" target="_blank" rel="nofollow">http://eathumblepie.blogspot.com</a>
nico dotti
Ranch Hand

Joined: Oct 09, 2007
Posts: 124
I would agree with Freddy that you should try something like this in a little test program. It's easier to remember things when you get to see them blow up...we have so much stuff to remember for this exam it's better if can remember an 'experience' not something we read. I don't know about you, but I playfully disbelieve any rule that's thrown at me until I try to disprove it and it blows up! The more of these little programs you right the better prepared you'll be. Moreover, you may learn that an expert has made a false assertion about how something works. It's sort of the 'hacker' mentality to test out concepts by coding proof. An even better hacker will think of little subtle things to do to the code that may or may not break it; through all these subtle changes they'll have intimate knowledge of what works and/or is allowed, and what blows up in their face LOL I'm just learning to do this myself, and sometimes I wish I could think of more creative ways to break the code. It seems obvious to me that most of the self test question in K&B are the results of such hacking around. I assert that it will be impossible to 1)trace the code in question 2) know exactly what type of output will be created (Runtime vs Compile Time, etc.,etc) without coding hundreds if not thousands of little tests. JMTC. Sorry for going off on a tangent, but I thought Freddy's comment needed a bit more explanation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: switch case problem
 
Similar Threads
Decoding Expresssions to values same as 'DECODE' function in Oracle
How close am I in getting this program right?
Nesting My If statements
to use if else or switch
return true if a integer is power of 2