当我为current5输入20时,minuteCurrent应该是240,但即使minuteCurrent超过240,部分也会继续工作。为什么?我尝试了更多的东西,但他们没有帮助。这是为什么 - 而计算是错误的?
import java.util.Scanner;
class Person {
String name;
int heartRatePer5;
int current5;
void alarm() {
for (int i = 0; i < 3; i++)
System.out.print("!!! ");
System.out.println();
}
void stopAlarm() {
System.out.println("Alarm stopped");
}
}
public class App{
public static void main(String[] args) {
Person person1 = new Person();
Scanner input = new Scanner(System.in);
System.out.println("Enter the current heart rate per 5 seconds: ");
person1.current5 = input.nextInt();
int minuteCurrent = person1.current5 * 12;
// minuteCurrent = 0;
do {
System.out.println("Normalizing.");
person1.stopAlarm();
//minuteCurrent = input.nextInt();
break;
}
while (minuteCurrent < 220);
}
}
http://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – Biffen
你的'do-while'将在第一次运行时总是停止,因为你最后有'break' 。你的意思是在它之前有一个if语句吗? –
请将您的代码修改为https://stackoverflow.com/help/mcve。整个“警报”是不需要的。 – Robert