月薪扣除 3500 起征點後,按級距稅率計算:
public class TaxCalc {
public static double calcTax(int salary) {
int taxable = salary - 3500;
if (taxable <= 0) return 0;
if (taxable <= 1500) return taxable * 0.03;
if (taxable <= 4500) return 1500 * 0.03 + (taxable - 1500) * 0.10;
if (taxable <= 9000) return 1500 * 0.03 + 3000 * 0.10 + (taxable - 4500) * 0.20;
// 其它級距同理...
return 0; // 簡化
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("輸入月薪: ");
int s = sc.nextInt();
System.out.printf("應納稅額: %.2f%n", calcTax(s));
}
}