首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

一个小疑点,大牛小牛都进来看看

2012-09-18 
一个小问题,大牛小牛都进来看看Java codeclass UnresponsiveUI{private volatile double d 1public Unr

一个小问题,大牛小牛都进来看看

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次的了。

热点排行