我想寫一個java程序,它確定如果一個數組的所有元素是質數。這裏是我的代碼:確定是否所有元素的數組是素數
boolean allPrimes(int[] ade){
int i = 0; //counter
boolean Prime = true; //initial boolean value
while (i<ade.length && !Prime){
if (p.isPrime(ade[i])) //function which determines if an int is prime.
Prime = true;
else
Prime = false;
i=i+1;
}
return Prime;
}
我不認爲這是正確的,因爲我做了一些測試,他們失敗了。我究竟做錯了什麼?感謝
wouldnt it'while(i
它是http://stackoverflow.com/questions/8114442/error-with-repetition-which-i-cant-spot – jjcastil