6 または 7 で割り切れる 1 ~ 100 の整数を表示するプログラムを作成する割り当て/プロジェクトがありますが、両方は割り切れません。以下に書いた方法ではうまくいきません。私のブール値は、質問が求めているものに対して正しいですか?
import acm program.*;
public class SixAndSeven extends ConsoleProgram {
public void run() {
for (int n = 1; n < 100; n++) {
boolean year = (n % 6 ==0) ||
(n % 7 ==0) &&
!(n % 6 == 0) &&
( n % 7 ==0);
if (year) {
println(year);
}
}
}
}