相关疑难解决方法(0)

如何使用BigInteger?

我有这段代码,但是没有用:

BigInteger sum = BigInteger.valueOf(0);
for(int i = 2; i < 5000; i++) {
    if (isPrim(i)) {
        sum.add(BigInteger.valueOf(i));
    }
}
Run Code Online (Sandbox Code Playgroud)

sum变量总是0.我做错了什么?

java biginteger

150
推荐指数
5
解决办法
33万
查看次数

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

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

java integer

76
推荐指数
6
解决办法
12万
查看次数

Java长号太大错误?

为什么我得到一个int数太大而long分配给min和max?

/*
long: The long data type is a 64-bit signed two's complement integer.
It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of         9,223,372,036,854,775,807 (inclusive).
Use this data type when you need a range of values wider than those provided by int.
*/
package Literals;

public class Literal_Long {
     public static void main(String[] args) {
        long a = 1;
        long b = 2;
        long min = -9223372036854775808;
        long max = 9223372036854775807;//Inclusive

        System.out.println(a);
        System.out.println(b);
        System.out.println(a + b);
        System.out.println(min); …
Run Code Online (Sandbox Code Playgroud)

java

22
推荐指数
2
解决办法
4万
查看次数

标签 统计

java ×3

biginteger ×1

integer ×1