b   =   System.in.read(); 
 System.out.println(b); 
 b   =   b   -   '0'; 
 System.out.println(b);                        假如我输入2为什么打印输出50,是怎么计算的

解决方案 »

  1.   

    字母 '2'  的unicode 编码就是50
    也就是16进制的 0x32;
      

  2.   

    看一下ASCII编码表也行。从键盘输入的都是字母哦!
      

  3.   


    其实你读进来的是一个char类型的.它打出了其ascII码,你可以查一下ascII编码表:
      

  4.   

    public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    int b;
    char c = '1';
    b = System.in.read();
    b = b - '0';
    System.out.println(b); }我试了一下,觉得没有什么问题呀!出来的结果不是你所说的那种结果呀!
      

  5.   

    public static void main(String args[]) {
    try {
    int i=System.in.read();
    System.out.println((char)i);
    } catch (IOException e) {
    e.printStackTrace();
    }
    }这样就可以了,将i强制转换一下
      

  6.   

     b   =   System.in.read();   ---> char b ='2' == int b = 50
     System.out.println(b); 
     b   =   b   -   '0';        --->  char '0' == int 48  --> 50 - 48 =2
     System.out.println(b);