編輯的問題被縮小:打印輸出/ s的嵌套if/else語句
ans1 = homeMortgage + annualTuition + annualCharity + healthCredit;
if(grossAnnualIncome <= ans1)
{
System.out.println("YOU OWE $0.00 IN TAXES!");
}
else if(grossAnnualIncome == 0)
{
System.out.println("You earned no income so you owe no taxes!");
}
else
{
//GROSS ANNUAL INCOME > 0 OUTPUT
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);
}
grossAnnualIncome < = ANS1正確輸出。
grossAnnualIncome == 0輸出您OWE $ 0.00的所有稅金!而不是你沒有收入,所以你不欠稅!
grossAnnualIncome> 0輸出正確。
也許你可以使用「其他如果」? – Andrew 2012-02-24 17:27:08
如果我輸入0作爲總的年收入,該方案只打印:「你沒有賺得收入,所以你欠稅!」這似乎是你期望的 - 不知道我明白你想要什麼...... – assylias 2012-02-24 17:28:24
需要有對於有收入的用戶的輸出,但是他們的稅收抵免超過了他們的納稅義務,因此輸出讀數您只需$ 0.00納稅!我可以把它展示出來,但是它會隨着它一起發佈大部分每年都會收到的東西,我不想要。 – Abweichung 2012-02-24 17:29:52