Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Selection Statements

 
Javix Protocol
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mani
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic