⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 caltax.java

📁 关于一些算法的例子
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -