我对else和if语句很好奇。 为什么我的系统无法像这样工作。我无法找到更正它的方法,但是它不会运行并显示错误,否则就没有if。
导入java.util.Scanner;
公共类Q2Prac5Extra {
public static void main(String args[])
{
final float x=0.0254f;
float height , weight;
int age;
String gender;
System.out.print("************Ideal Weight Calculator************\n\nPlease enter your gender: ");
gender = input.nextLine();
System.out.print("Please enter your height: ");
height = input.nextFloat();
System.out.print("Please enter your age: ");
age = input.nextInt();
if(age<18)
System.out.print("bye");
else if (height<1.22);
System.out.print("bye bye bye");
else
{
if(gender.equals("male"))
weight = 29.2f + 1.9f*((height-1.22f)/x);
else
weight = 28.6f + 1.7f*((height-1.22f)/x);
System.out.print("\n\nThe ideal weight of this person is " + String.format("%.0f",weight) + "kg\n\n");
}
} }