java吧 关注:1,243,960贴子:12,719,854
  • 4回复贴,共1

跪求大神解答一段简单代码?

只看楼主收藏回复

为啥下面这段代码再输入1时,运行结果是entry而win a Car!
public class Switch_Test
{
public static void main(String args[])
throws java.io.IOException
{
int a;
System.out.println("Enter a number from 1--3:");
a=(int)System.in.read();
switch(a)
{
case 1:System.out.println("win a Car!");break;
case 2:System.out.println("picked the goat!");break;
case 3:System.out.println("get to keep your 100!");
break;
default:System.out.println("entry");
}
}
}


1楼2015-03-11 18:28回复
    System.in.read()返回的是输入数值的 ASCLI 码


    IP属地:安徽来自Android客户端2楼2015-03-11 18:51
    收起回复