我希望Java询问用户意味着他获得高于0如何打印这个循环
System.out.print("\tEnter your weight in Kilogram: ");
double weight = in.nextDouble();
System.out.print("\tEnter your height in Centimeter: ");
double height = in.nextDouble();
if (weight <= 0 || height <= 0) {
while (true) {
System.out.println("Wrong entry for weight or height... try again");
}
}
String clinic = "NUTRITION";
我不能这样做既体重或身高而不会导致一个无限循环
这怎么我希望我的输出:
System.out.println("Enter the name (first and last): Omar\n"
+ "Enter your national ID number: 9821444\n"
+ "Enter your age: 30\n"
+ "Enter your mobile number (###-###-####): 055-098-1122\n"
+ "Enter your weight in Kilogram: 0\n"
+ "Enter your height in Centimeter: 176\n"
+ "Wrong entry for weight or height... try again\n"
+ "Enter your weight in Kilogram: 77\n"
+ "Enter your height in Centimeter: 0\n"
+ "Wrong entry for weight or height... try again\n"
+ "Enter your weight in Kilogram: 77\n"
+ "Enter your height in Centimeter: -176\n"
+ "Wrong entry for weight or height... try again\n"
+ "Enter your weight in Kilogram: 77\n"
+ "Enter your height in Centimeter: 176");
相关:http://stackoverflow.com/questions/36845766/how-do-i-simplify -this-integer-validation/36846116#36846116 – Gendarme
这不应该被标记为“javascript”,因为这是一个Java问题。 – AmericanUmlaut