我不确定如何才能使最终的' else if if '语句正常工作。
有问题的代码目前已被删除,位于程序的最底层。阅读上面的其他“ else if else ”语句可能会让您更好地了解我的思维过程。
即我不确定如何制作最终的' else if ',因为它没有定义的最大值。
else if((gross_income >= 80001) && (gross_income <= 180000))
{
gross_income = gross_income - 80000;
tax_payable = tax_payable + 17547;
for(i = 1; i <= gross_income; i++)
{
tax_payable = tax_payable + 0.37;
}
System.out.print("\n\n");
System.out.print("YOU MUST PAY $" + df.format(tax_payable) + " IN TAX!");
System.out.print("\n\n");
}
// else if(gross_income >= 180001)
// {
// gross_income = gross_income - 180000;
// tax_payable = tax_payable + 54547;
//
// for(?????)
// {
// tax_payable = tax_payable + 0.45;
// }
//
// System.out.print("\n\n");
// System.out.print("YOU MUST PAY $" + df.format(tax_payable) + " IN TAX!");
// System.out.print("\n\n");
// }
}
}
答案 0 :(得分:1)
这样做 - 总是试图阻止双重代码(例如,计算只进行一次,唯一改变的是税率):
double perc = 0.0;
if( gross_income < 80001 )
{
perc = 0.16; // dont know american tax limits, so lets pretend 0.16
}
else if( gross_income >= 80001 && gross_income < 180001 )
{
perc = 0.37;
}
else
{
perc = 0.45;
}
tax_payable = gross_income * perc;
System.out.print("\n\n");... and so on