這是我迄今爲止的代碼。我需要它從一個Int轉換爲雙精度
我需要if語句的最後轉換爲雙
public static void main(String[] args) {
double skill = 0; double hours = 0; double overTime= 0.5; int insurance =0;
String[] choices = {"Medical Insurance", "Dental Insurance", "Long-Term Disability Insurance"};
double MedicalInsuranceCount = 32.50;
double DentalInsuranceCount = 20.00;
double LongTermDisabilityInsuranceCount = 10.00
if (skill >= 20.00 && skill <=22.00)
insurance = JOptionPane.showOptionDialog(
null // Center in window.// prompts the user to select a button
, "Types of Insurance options" // Message
, "Insurance option" // Title in titlebar
, JOptionPane.YES_NO_OPTION // Option type
, JOptionPane.PLAIN_MESSAGE // messageType
, null // Icon (none)
, choices // Button text as above.
, "None of your business" // Default button's label
);
switch (insurance)
{
case 0:
MedicalInsuranceCount++;
break;
case 1:
DentalInsuranceCount++;
break;
case 2:
LongTermDisabilityInsuranceCount++;
break;
default:
//... If we get here, something is wrong. Defensive programming.
JOptionPane.showMessageDialog(null, "Unexpected response " + insurance);
}
// this is where the problem is I think.
if(insurance == 0)
insurance = Math.round((float)MedicalInsuranceCount);
else if(insurance == 1)
insurance = Math.round((float)DentalInsuranceCount);
else if(insurance == 2)
insurance = Math.round((float)LongTermDisabilityInsuranceCount);
System.out.println(insurance);
}
}
香港專業教育學院嘗試使用Double.PasreDouble但失敗和Math.round(浮動)是工作
它是什麼,輸出什麼是你期待的,什麼是錯'Math.round(浮動)'是否行得通? – BitNinja 2014-08-31 20:09:50
您正在使用「保險」變量用於多種用途。首先,你需要整理出來,然後我們可以幫你(如果仍然有必要的話) – ljgw 2014-08-31 20:14:06
你的第一個if block將永遠不會**,因爲當if塊出現時,技能總是0。 – 2014-08-31 22:07:24