本帖最后由 葛迅 于 2013-3-29 21:07 编辑
希望有大神粗线 用switch 替代下列If语句 重新编写 感激不尽!
PS:有志同道合者一起参加 6月7号的云计算大会吗?- class Tax
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- //提示用户输入合适的身份
- System.out.print("0-单身纳税人,1-已婚共同纳税人,\n"+"2-已婚单独纳税人,3-家庭户主纳税人\n"+"输入对应的身份:");
- int status = input.nextInt();
-
- //提示用户输入 收入
- System.out.print("Enter the taxable in come:");
- double income = input.nextDouble();
-
- //计算税率
-
- double tax = 0;
-
- if (status == 0)
- {
- if (income <= 8350)
- tax = income * 0.10;
- else if (income <= 33950)
- tax = 8350 * 0.10 + (income - 8350)*0.15;
- else if (income <= 82250)
- tax = 8350 * 0.10 + (33950 -8350) * 0.15+ (income - 33950) * 0.25;
- else if (income <= 171550)
- tax = 8350 * 0.10 + (33950 -8350) * 0.15+ (82250 - 33950) * 0.25+(income - 82250)*0.28;
- else if (income <= 372950)
- tax = 8350 * 0.10 + (33950 -8350) * 0.15+ (82250 - 33950) * 0.25+(171550 - 82250)*0.28+(income-171550) * 0.33;
- else
- tax = 8350 * 0.10 + (33950 -8350) * 0.15+ (82250 - 33950) * 0.25+(171550 - 82250)*0.28+(372950-171550) * 0.33+
- (income - 372950) * 0.35;
- }
-
- else
- {
- System.out.println("Error:invalid status");
- System.exit(0);
- }
-
-
-
- System.out.println("Tax is"+(int)(tax * 100)/100.0);
-
- }
- }
复制代码 |