这段程序怎么解释?
package xyz;
import java.util.*;
public class test {
public static void main(String[] args) {
int b = 0;
ArrayList a = new ArrayList();
System.out.println( "enter two num ");
while (true) {
try {
b = System.in.read();
// System.out.println( "b is "+b);
} catch (Exception e) {
System.out.println(e.getMessage());
}
if (b == '\r ' || b == '\r ')
break;
else {
// System.out.println( "b is "+b);
int num = b - '0 '; // 这是为什么?
// System.out.println( "num is "+num);
try {
a.add(new Integer(num));
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
int sum = 0;
Iterator v = a.iterator();
while (v.hasNext()) {
sum += (Integer) v.next();
}
System.out.println(sum);
}
}
}
int num = b - '0 ';
这一句话是什么意思?
谢谢
------解决方案--------------------b是一个整型变量, 'a '在这里会取其ascii码值:48
也就是相当于:int num=b-48;