- Java code
class UnresponsiveUI{ private volatile double d = 1; public UnresponsiveUI() throws Exception { while(d > 0) { d = d + (Math.PI + Math.E) / d; System.in.read(); System.out.println(d); } }} public static void main(String[] args) throws Exception { new UnresponsiveUI(); // Must kill this process //new ResponsiveUI(); //System.in.read(); //System.out.println(d); }}
在控制台输入1,为什么一下子打印出来:
6.859874482048838
7.714099220035395
8.473730943053596
------解决方案--------------------
输出一下System.in.read() 的值就能看出来了,
你回车的时候\r\n有两个字节,加上你的1,就是3个字节,read一次只有一个字节,够读3次的了。