System.in是原始的输入字节流,它返回输入的每个字节,
你没输入值的时候键入的回车其实是'\r\n',也就是'\10\13'所以
b被赋值为10.
由于平台关系(dos、windows下) \n会被自动转义为'\r\n'所以 r=='\n'判断失败.
r是一个字节嘛.
你没输入值的时候键入的回车其实是'\r\n',也就是'\10\13'所以
b被赋值为10.
由于平台关系(dos、windows下) \n会被自动转义为'\r\n'所以 r=='\n'判断失败.
r是一个字节嘛.
DataInputStream in = new DataInputStream(System.in);
然后从in里面读入.具体方法查查文档吧
这段程序是个基于Symantec Cafe的例子。
是否意味着只能在Symantec Cafe里通过。
用其他编译器或在win/dos环境下就不行呢?
用BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String strInput;
strInput=stdin.readLine();
StringTokenizer st=new StringTokenizer(strInput);
String[] temp=new String[st.countTokens];
int i=0;
while(st.hasMoreTokens())
temp[i++]=st.nextToken();
a=Integer.parsteInt(temp[0]);
r=Integer.parseInt(temp[1]);