當我運行這個程序時,它被卡在一個要求我輸入值的循環中,並繼續添加一個和數。雖然這正是它應該做的事,但如果我輸入一個可以被6或17整除的數字,循環不會結束。可以解釋爲什麼?簡單可分性
import java.util.Scanner;
public class DivisibleBy6or17 {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Enter Value: ");
int one = in.nextInt();
int sum=0;
while (one % 6 != 0||one % 17 != 0) {
System.out.print("Enter Value: ");
one = in.nextInt();
sum++;
}
System.out.print("Numbers read: " + sum);
}
}
''|| - >''&& ... – Mysticial
嘗試輸入102 :) –
一個'%6 = 0 ||一個17%= 0'嘗試換!在括號中,因爲很難得到正在發生的事情。也可能泄漏優先級混淆問題 – mishadoff