我正在爲即將到來的Java測試進行修訂,而且我陷入了一個部分,我無法解決它。檢查兩個整數之間的數字
問:從Int A到Int B取整數2,如果X可以被6或5整除但不能同時爲2,並且在每10個數字後打印一個新行。
下面是我當前的代碼:
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int numOne = sc.nextInt();
int numTwo = sc.nextInt();
int line = 1;
while (numTwo > numOne) {
if (line%11==0){
System.out.println("");
}
if ((numOne % 5 == 0) && (numOne % 6 != 0)) {
System.out.print(numOne + " ");
line++;
}
if ((numOne % 6 == 0) && (numOne % 5 != 0)) {
System.out.print(numOne + " ");
line++;
}
}
numOne++;
}
謝謝!我沒有意識到我把增量放在了外面 – gymcode