This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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