如果用户键入“C”,我只希望输出为 12.0,与键入“H”相同。问题是输入被存储为正确的字符串吗?我试图通过 Double.parseDouble 将字符串转换为双精度
import java.util.Scanner;
public class Elements {
Scanner input=new Scanner(System.in);
public static final double H = 1.0;
public static final double Li = 6.9;
public static final double Be = 9;
public static final double B = 10.8;
public static final double C = 12.0;
public double output() {
return C ; // I want the user to choose the variable to return
}
}