编程珠玑-课后练习题3
计算税率表达式简化
1 package third; 2 3 public class SimpleTax { 4 public static double getTax(double income) { 5 double index = (income - 2200) / 500; 6 double tax = 0; 7 double startRate = 0.14; 8 if (index <= 0) { 9 tax = 0; 10 } else { 11 for (int i = 1; i <= index; i++) { 12 tax = tax + startRate * 500; 13 startRate += 0.01; 14 } 15 tax += (income - 2200 - 500 * ((int) index)) * startRate; 16 } 17 return tax; 18 } 19 20 public static void main(String[] args) { 21 System.out.println(getTax(3700)); 22 } 23 24 }

浙公网安备 33010602011771号