三个小朋友放炮,每个小朋100个炮,炮点就炸,
在不考虑安全问题的前提下,第一个小朋友每隔1秒钟点一次第二个小朋友,
每隔2秒钟点一次第三个小朋友,每隔3秒钟点一次。问能听到多少声?
int count = 0;
boolean isShootingB = false;
boolean isShootingC = false;
for (int time = 1; time <= 100; time++) {
if (time % 2 == 0) {
isShootingB = true;
}
if (time % 3 == 0) {
isShootingC = true;
}
if (isShootingB && isShootingC == false) {
count++;
}
if (isShootingC && isShootingB == false) {
count++;
}
if (isShootingB && isShootingC) {
count+=2;
}
isShootingB = false;
isShootingC = false;
}
for (int time = 101; time <= 200; time++) {
if (time % 2 == 0 && time % 3 == 0) {
count++;
}
}
System.out.println(count + " 总共听到响声: " + (300 - count));