import java.io.IOException;
public class SwitchDemo {
/**
* @param args
*/
public static void main(String[] args) throws IOException
{
int a;
a=(int)System.in.read();
String season;
switch(a)
{
case 12:
case 1:
case 2:
season="冬季";
break;
case 3:
case 4:
case 5:
season="春季";
break;
case 6:
case 7:
case 8:
season="夏季";
break;
case 9:
case 10:
case 11:
season="秋季";
break;
default:
season="错!";
break;
}
System.out.println(a+"月份属于:"+season);
// TODO Auto-generated method stub
}
}
输入8,结果‘56月份属于错!’ 不是应该‘8月份属于夏季’么?
输入d,结果忘了,好像是‘48月份属于错’
该怎么改??
改成了:a=Integer.parseInt(System.in.read());
但是run的时候出错,提示
‘The method parseInt(String) in the type Integer is not applicable for the arguments (int) ’
a=Integer.parseInt(System.in.read());
但是run的时候出错,提示
‘The method parseInt(String) in the type Integer is not applicable for the arguments (int) ’
Int a=System.in.read()-48;
原因是输入返回的是字符,不是你要的数字。