//我想在控制臺中插入一個十進制數(如 1.85)到 String groesse,我還希望它在 bmi 等式中。我怎么做?
public static void main(String[] args) {
Locale.setDefault(Locale.US);
PrintWriter out = new PrintWriter(System.out);
bmiRechner(out);
out.flush();
}
public static void bmiRechner(PrintWriter out) {
Scanner sc = new Scanner (System.in);
String = groesse;
out.println("Sch?nen Guten Tag");
out.flush();
out.println("Geben Sie ihre K?rpergr??e in Metern an");
out.flush();
groesse = sc.next();
out.println("Geben Sie nun ihr K?rpergewicht in Kilogramm ein");
out.flush();
int gewicht = sc.nextInt();
double bmi = gewicht / Math.pow(groesse, 2);
out.println("Das ist Ihr BMI: " bmi);
}
}
uj5u.com熱心網友回復:
我怎么做?
好的,所以您想從控制臺讀取用戶輸入。這樣做,而不是...
groesse = sc.next();
用
// This line will get the input line
groesse = sc.nextLine().trim();
// This will get the numeric value of the input
double groesse = Double.valueOf(groesse)
這同樣適用于其他測量。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/354179.html
上一篇:在Java中顯示布林值時遇到問題
