wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Selection Statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Selection Statements" Watch "Selection Statements" New topic
Author

Selection Statements

Javix Protocol
Ranch Hand

Joined: Mar 21, 2000
Posts: 57
public class witch {
public static void main(String args[]) {
byte b = 100;
switch(b){
case 100:
System.out.println("100");
break;
case 200:
System.out.println("200");
break;
case 300:
System.out.println("300");
break;
}
}
}

Why there is compiler error??Maha anna specify please!


------------------
The Javix


Write Once , Run Anytime ,Anywhere Forever And Smile Happily.
Mani
Ranch Hand

Joined: Apr 20, 2000
Posts: 50
Problem comes with the value you are using in the last two case statements.The range of values for byte is between -128 and 127.
If you remove those two case statements or give values within the range of byte, the code will compile.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Selection Statements
 
Similar Threads
Default in Switch
about switch structure
Switch
assigning an integer literal to a byte
switch type