caltax.java

来自「关于一些算法的例子」· Java 代码 · 共 39 行

JAVA
39
字号
public class CalTax{
	//计算个人所得税
	public static void main(String args[]){
		int taxLevel[] = {
			0, 500, 2000, 5000, 20000, 40000, 60000, 80000, 100000
		};
		double taxRate[] = {
			0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5
		};

		double income = 7000; //monthly income

		if (income <= 2000){
		       System.out.println("No need to pay tax");
		       return;
		}

		int index = 0;
		double taxIncome = income - 2000;
		while ( taxIncome > taxLevel[index] ){
			index++;
			if (index == taxLevel.length) break;
		}
		index--;


		double tax = 0;
		while (index >= 0 ){
			tax += (taxIncome - taxLevel[index] ) * taxRate[index];
			taxIncome = taxLevel[index];
			index--;
		}


		System.out.println("Personal Tax Should pay : "+ tax);
		System.out.println("Income after tax : " + (income - tax));
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?