这个程序有什么问题 [英] what's wrong with this program

查看:28
本文介绍了这个程序有什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码片段:

class WhileTest
{
    public static void main(String s[])
    {
        int x=12;
        while(x<13)
        {
            x--;
        }
        System.out.println(x);
    }
}

上述程序的输出为:2147483647

为什么会这样?

ideone 上的代码

推荐答案

x 递减然后下溢到达 Integer.MAX_VALUE

x is decremented and then underflows reaching Integer.MAX_VALUE

这篇关于这个程序有什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆