小编Mou*_*rie的帖子

尽管使用标识符"long",但获取负值/错误值

我试图计算第一个,甚至四百万个斐波那契数的总和.但是,过了一段时间,即使我使用标识符long,只有在值变大时才打印出Y值.

这些是起始值:

long amount = 4000000;
long x = 1;
long y = 2;
long sum = 2;
Run Code Online (Sandbox Code Playgroud)

这是一个for循环,总结并在程序运行时打印出数字.

for (int i = 0; i < amount - 1; i++) {
    if (x > y) {
        y = x + y;
        if (y % 2 == 0) {
            sum += y;
        }           
        System.out.println("X: " + x);
    } else {
        x = x + y;
        if (x % 2 == 0) {
            sum += x;
        }   
        System.out.println("Y: " + y);
    } …
Run Code Online (Sandbox Code Playgroud)

java numbers long-integer

1
推荐指数
1
解决办法
210
查看次数

标签 统计

java ×1

long-integer ×1

numbers ×1