日期:2014-05-20  浏览次数:20561 次

输出流
BufferedReader nw =new BufferedReader(new InputStreamReader(System.in));
  int c=nw.read();
            System.out.print(c);
为什么我输入10,输出的结果是49呢?
------最佳解决方案--------------------
那是1的ASCII码
------其他解决方案--------------------
引用:
那是1的ASCII码

+1
看read方法的说明:
The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
返回的是它读到的一个字符,你这里也就是1,1对应的ascii码值就是49.
------其他解决方案--------------------
引用:
那是1的ASCII码

  哪怎么修改呢?
------其他解决方案--------------------
我一般都用Scanner类
Scanner sc=new Scanner(System.in);
int c=sc.nextInt();
System.out.print(c);
当然还有别的方法,可以自己查一下API