每日一练作业
中国的个税计算方法:
应税所得为税前收入扣除2000 元(起征点),然后超出部分,按照以下税率
收税:
500 5%
500-2000 10%
2000-5000 15%
5000-20000 20%
20000-40000 25%
40000-60000 30%
60000-80000 35%
80000-100000 40%
100000 -? 45%
例:若月收入15000,则应税所得为15000-2000=13000;总的个人所得税为
(13000-5000)*20% + (5000-2000)*15% + (2000-500)*10% + 500*5%= 2225
要求:读入一个整数,表示税前收入,输出应当缴纳的个人所得税和税后实际收入。
1 package com.yirose.java8.string; 2 import java.util.Iterator; 3 import java.util.LinkedHashMap; 4 import java.util.Map; 5 import java.util.Scanner; 6 7 public class revenueDemo { 8 public static void main(String[] args) { 9 // 个税汇率 10 Map<Integer, Double> map = new LinkedHashMap<Integer, Double>(); 11 map.put(100000, 0.45); 12 map.put(80000, 0.40); 13 map.put(60000, 0.35); 14 map.put(40000, 0.30); 15 map.put(20000, 0.25); 16 map.put(5000, 0.20); 17 map.put(2000, 0.15); 18 map.put(500, 0.10); 19 map.put(0, 0.05); 20 21 Scanner sc = new Scanner(System.in); 22 System.out.println("请输入你的税前薪水:"); 23 int pre_tax = sc.nextInt(); // 读取整型输入 24 int salary = pre_tax - 2000; 25 double revenue = 0; 26 27 // 循环查询 28 Iterator iter = map.keySet().iterator(); 29 while (iter.hasNext()) { 30 Integer key = (Integer) iter.next(); 31 double val = map.get(key); 32 if (salary > key) { 33 salary = salary - key; 34 double revenue0 = salary * val; 35 revenue = revenue + revenue0; 36 salary = key; 37 } 38 } 39 // 输出 40 System.out.println("税前薪水:" + pre_tax); 41 System.out.println("实际薪水:" + (pre_tax - revenue)); 42 System.out.println("交税:" + revenue); 43 } 44 }