對不起,再次編輯這個,而不是另一個帖子,我想我會問這裏。嵌套如果/其他陳述
public static void main(String[] args)
{
// TODO code application logic here
char response = 0;
double grossAnnualIncome = 0.0;
double annualTuition = 0.0;
double annualCharity = 0.0;
double homeMortgage = 0.0;
double healthCredit = 0.0;
double annualAfterTaxes = 0.0;
double monthlyAfterTaxes = 0.0;
double taxAt17 = 0.0;
double taxableIncome = 0.0;
double ans1 = 0.0;
Scanner input = new Scanner(System.in);
System.out.printf("Please enter your gross annual income or 0 for none: ");
grossAnnualIncome = input.nextDouble();
if(grossAnnualIncome > 0)
{
System.out.printf("Please enter your annual tuition and expenses for higher education or 0 for none: ");
annualTuition = input.nextDouble();
System.out.printf("Please enter your annual charitable contributions or 0 for none: ");
annualCharity = input.nextDouble();
System.out.printf("Please enter the annual interest paid for your home mortgage or 0 for none: ");
homeMortgage = input.nextDouble();
input.nextLine();
System.out.printf("Did you purchase health insurance through your employer or outside the workplace?"
+ " Enter 'Y' or 'N': ");
response = input.nextLine().charAt(0);
if(Character.toUpperCase(response) == 'Y')
{
System.out.printf("Are you filing as a family? Enter 'Y' or 'N': ");
response = input.nextLine().charAt(0);
if (Character.toUpperCase(response) == 'Y')
{
healthCredit = 3500;
}
else
{
if(Character.toUpperCase(response) == 'N')
{
System.out.printf("Are you filing as single? Enter 'Y' or 'N': ");
response = input.nextLine().charAt(0);
}
if(Character.toUpperCase(response) == 'Y')
{
healthCredit = 2000;
}
}
}
else
{
healthCredit = 0;
}
taxableIncome = grossAnnualIncome - homeMortgage - annualTuition - annualCharity - healthCredit;
taxAt17 = taxableIncome * .17;
annualAfterTaxes = grossAnnualIncome - taxAt17;
monthlyAfterTaxes = annualAfterTaxes/12;
ans1 = homeMortgage + annualTuition + annualCharity + healthCredit;
System.out.printf("\nYOUR TAXES\n\n"
+ "Gross Annual Income: %,.0f\n\n"
+ "Deductions: \n"
+ "\tHigher Education: %,.0f\n"
+ "\tCharitable Contributions: %,.0f\n"
+ "\tHome Mortgage Interest: %,.0f\n"
+ "\tHealth Insurance Tax Credit: %,.0f\n\n"
+ "Tax at 17%%: %,.0f\n"
+ "Annual Income After Taxes: %,.0f\n"
+ "Monthly Income After Taxes: %,.0f", grossAnnualIncome, annualTuition, annualCharity,
homeMortgage, healthCredit, taxAt17, annualAfterTaxes, monthlyAfterTaxes);
}
if(grossAnnualIncome <= 0)
{
System.out.printf("You earned no income so you owe no taxes!");
}
System.exit(0);
}
}
我的兩個輸出都是正確的,但是我對最後一個輸出有問題。
我最後的輸出結果需要閱讀「您只需要0.00美元的稅金!」
當我代碼:
if (grossAnnualIncome <= ans1)
{
System.out.printf("YOU OWE $0.00 IN TAXES!");
}
它顯示了從grossAnnualIncome> 0輸出。
打印你給的輸入......還有你在哪一行得到這個異常? – 2012-02-24 05:02:59
我不確定哪一行,上面的代碼片段就是發佈的異常錯誤。 至於我輸入: 請輸入您的年收入額或0表示無:25000 請輸入您每年的學費和費用高等教育或0表示無:2500 請輸入您的年度慈善捐款或0表示無:100 請輸入您的住房抵押貸款的年利息或0爲零:0 您是否通過您的僱主或在工作場所以外購買健康保險?輸入'Y'或'N':y 您是否正在申請家庭?輸入'Y'或'N':y 然後我收到錯誤消息。 – Abweichung 2012-02-24 05:07:12
家庭新聞N並告訴我你得到... – 2012-02-24 05:12:41