当前位置: 代码迷 >> Java相关 >> 求教输入问题
  详细解决方案

求教输入问题

热度:311   发布时间:2008-10-08 12:16:14.0
求教输入问题
import java.io.*;
class ex6_5_2{
    public static void main(String[] args)throws IOException{
        InputStreamReader isr=new InputStreamReader(System.in);
        BufferedReader bfr=new BufferedReader(isr);
        System.out.print("请输入数字: ");
        int shuru=bfr.read();
        System.out.println("你输入的数字是:"+shuru);
    }
}
上面是我学写的代码,但是我输入的和系统输出的不是同一个数字,为什么?刚学Java没办法!
搜索更多相关的解决方案: 输入  

----------------解决方案--------------------------------------------------------
因为你输入的是一个字符数字,当它赋值给int时,要转化为ASCII值。
比如输入5 ,其实它是‘5’
----------------解决方案--------------------------------------------------------
主要是bfr.read()它只读一个字符。
然后就如ls所说了。
----------------解决方案--------------------------------------------------------
一段时间没来了,现在java好强大啊。。。转换integer
----------------解决方案--------------------------------------------------------
那要怎么改呢?
----------------解决方案--------------------------------------------------------
int shuru=Integer.pasInt32(bfr.read());

应该可以了
----------------解决方案--------------------------------------------------------
你为什么不用util.Scanner;包??
----------------解决方案--------------------------------------------------------
  相关解决方案