編程和處理一些項目歐拉問題的新手。我相信我陷入了無限循環。我已經把它寫在紙上了,一切似乎都沒問題。我錯過了什麼?陷入無限循環? (Java)
public class Euler2 {
public static void main(String[] args) {
int i = 1;
int j = 2;
int fib = 0;
int sum = 2;
//Sum of even Fibonacci numbers
while(fib < 10);{
fib = (i + j);
if(fib % 2 == 0);{
sum = sum + fib;
}
i = j; j = fib;
}
System.out.println(sum);
}
}
首先你應該擺脫'的;'在'while'聲明:'而(FIB <10);' – user2004685
http://stackoverflow.com/questions/2610679/whats-wrong- with-this-while-loop – Michael
同樣爲'if(fib%2 == 0); {'line(應該是if(fib%2 == 0){')。 – mc10