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); }我试了一下,觉得没有什么问题呀!出来的结果不是你所说的那种结果呀!
public static void main(String args[]) { try { int i=System.in.read(); System.out.println((char)i); } catch (IOException e) { e.printStackTrace(); } }这样就可以了,将i强制转换一下
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);
也就是16进制的 0x32;
其实你读进来的是一个char类型的.它打出了其ascII码,你可以查一下ascII编码表:
// TODO Auto-generated method stub
int b;
char c = '1';
b = System.in.read();
b = b - '0';
System.out.println(b); }我试了一下,觉得没有什么问题呀!出来的结果不是你所说的那种结果呀!
try {
int i=System.in.read();
System.out.println((char)i);
} catch (IOException e) {
e.printStackTrace();
}
}这样就可以了,将i强制转换一下
System.out.println(b);
b = b - '0'; ---> char '0' == int 48 --> 50 - 48 =2
System.out.println(b);