我試圖在此代碼中插入「if」語句,但它不能很好地工作。其固定工資和獎勵(37.28 * 1.32)將給予94,261.02一次。低於94,261.02只是一個普通的37.28佣金。所有iny「int」行用紅色加下劃線顯示!分數。所以我試圖找出問題:如何使用「if」語句
System.out.println("Enter your annual sales");
String annual = input.nextLine();
int salary = 7550281;
int commission = 38_28;
int compensation = Integer.parseInt(annual) * commission + salary;
System.out.println("compensation is: "+compensation);
if (Integer.parseInt(annual) < 92416_02) {
int salary = 7550281;
int commission = 37_28 * 1_32;
int compensation = Integer.parseInt(annual) * commission + salary;
System.out.println("compensation is: "+compensation);
} else if (Integer.parseInt(annual) > 92416_02){
int salary = 7550281;
int commission = 38_28;
int compensation = Integer.parseInt(annual) * commission + salary;
System.out.println("compensation is: "+compensation);
}
謝謝。
@MadProgrammer Java 1.7允許在數值中使用_,以獲得更好的表示/可讀性。 – Batty
自編譯器版本「1.6」以來我們不支持使用'_'的數字,現在我們就像'7' ... –
@Batty嚴重嗎?這使得更好的介紹:P – MadProgrammer