输入性别(M或F)后,程序将立即结束,而无需进入切换状态
我尝试将'string'更改为“ string”,但什么都没有改变。我认为那会有所作为
import java.util.Scanner;
public class FemurHumerus {
public static void main(String[] args) {
String gender;
double FemHum;
double MaleHum;
double FemFem;
double MaleFem;
int FemHumR;
int MaleHumR;
int FemFemR;
int MaleFemR;
Scanner scan = new Scanner(System.in);
System.out.println("What is your gender? (M or F): ");
gender = scan.nextLine();
switch (gender) {
case "F":
System.out.print("Enter femur length: ");
FemFem = in.nextInt();
FemFemR = (int) (FemFem*1.94+28.7);
System.out.print("Enter humerus length: ");
FemHum = in.nextInt();
FemHumR = (int) (FemHum*2.8+28.2);
System.out.println("Height based on femur: "+FemFemR);
System.out.println("Height based on humerus: "+FemHumR);
break;
case "M":
System.out.print("Enter femur length: ");
MaleFem = in.nextInt();
MaleFemR = (int) (MaleFem*1.88+32);
System.out.print("Enter humerus length: ");
MaleHum = in.nextInt();
MaleHumR = (int) (MaleHum*2.9+27.9);
System.out.println("Height based on femur: "+MaleFemR);
System.out.println("Height based on humerus: "+MaleHumR);
break;
default:
System.out.println("Gender not sprecified.");
break;
}
}
}
预期输出应为基于股骨和肱骨的特定性别的身高