java 实现个税计算器
时间: 2024-04-22 15:26:04 浏览: 238
好的,下面是一个使用 Java 实现个税计算器的示例代码:
```java
import java.util.Scanner;
public class IncomeTaxCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入税前工资:");
double salary = scanner.nextDouble();
System.out.print("请输入社保公积金:");
double socialSecurity = scanner.nextDouble();
System.out.print("请输入专项扣除:");
double deduction = scanner.nextDouble();
double taxableIncome = salary - socialSecurity - deduction - 5000;
double tax = 0;
if (taxableIncome <= 0) {
tax = 0;
} else if (taxableIncome <= 3000) {
tax = taxableIncome * 0.03;
} else if (taxableIncome <= 12000) {
tax = taxableIncome * 0.1 - 210;
} else if (taxableIncome <= 25000) {
tax = taxableIncome * 0.2 - 1410;
} else if (taxableIncome <= 35000) {
tax = taxableIncome * 0.25 - 2660;
} else if (taxableIncome <= 55000) {
tax = taxableIncome * 0.3 - 4410;
} else if (taxableIncome <= 80000) {
tax = taxableIncome * 0.35 - 7160;
} else {
tax = taxableIncome * 0.45 - 15160;
}
System.out.println("应缴纳个人所得税:" + String.format("%.2f", tax) + " 元");
}
}
```
在这个示例代码中,我们使用了 Java 的 Scanner 类来接收用户输入的税前工资、社保公积金和专项扣除等信息,并计算出应缴纳的个人所得税金额。计算个人所得税的公式与 HTML 表单的示例代码中的相同。通过使用 `String.format()` 方法来保留两位小数输出结果。
阅读全文