“整数太大"600851475143 的错误消息 [英] "Integer number too large" error message for 600851475143

查看:23
本文介绍了“整数太大"600851475143 的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class Three {
    public static void main(String[] args) {
        Three obj = new Three();
        obj.function(600851475143);
    }

    private Long function(long  i) {
        Stack<Long> stack = new Stack<Long>();

        for (long j = 2; j <= i; j++) {
            if (i % j == 0) {
                stack.push(j);
            }
        }
        return stack.pop();
    }
}

当上面的代码运行时,它会在obj.function(600851475143);行产生一个错误.为什么?

When the code above is run, it produces an error on the line obj.function(600851475143);. Why?

推荐答案

600851475143 不能表示为 32 位整数(类型 int).它可以表示为 64 位整数(类型 long).Java 中的长文本以L"结尾:600851475143L

600851475143 cannot be represented as a 32-bit integer (type int). It can be represented as a 64-bit integer (type long). long literals in Java end with an "L": 600851475143L

这篇关于“整数太大"600851475143 的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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