凯哥学堂
标题:
练习If else
[打印本页]
作者:
可可
时间:
2017-8-24 22:35
标题:
练习If else
个人所得税计算
package com.kaige123.ifelse;
/**
* 凯哥
*/
public class TestIfElse {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("请输入您的工资:");
int gz = input.nextInt();
int ss = 0;
gz -= 3500;
if (gz >= 0) {
if (gz < 1500) {// 第一个等级 0.3 0
ss = (int) (gz * 0.03f);
} else {
if (gz < 4500) {// 10 105
ss = (int) (gz * 0.1f - 105);
} else {
if (gz < 9000) {// 20 555
ss = (int) (gz * 0.2f - 555);
} else {
if (gz < 35000) {// 25 1005
ss = (int) (gz * 0.25f - 1005);
} else {
if (gz < 55000) {// 30 2755
ss = (int) (gz * 0.30f - 2755);
} else {
if (gz < 80000) {// 35 5505
ss = (int) (gz * 0.35f - 5505);
} else {
ss = (int) (gz * 0.45f - 13505);
}
}
}
}
}
}
System.out.println("您所有要交付的税务:" + ss + "元");
System.out.println("剩下的工资:" + (gz+3500 - ss) + "元");
} else {
System.out.println("您的工资还不在个人所得税之内,加油!");
}
}
}
改进if else
package com.kaige123.ifelse;
/**
* 凯哥
*/
public class TestIfElse {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("请输入您的工资:");
int gz = input.nextInt();
int ss = 0;
gz -= 3500;
if (gz >= 0) {
if (gz < 1500) {// 第一个等级 0.3 0
ss = (int) (gz * 0.03f);
} else if (gz < 4500) {// 10 105
ss = (int) (gz * 0.1f - 105);
} else if (gz < 9000) {// 20 555
ss = (int) (gz * 0.2f - 555);
} else if (gz < 35000) {// 25 1005
ss = (int) (gz * 0.25f - 1005);
} else if (gz < 55000) {// 30 2755
ss = (int) (gz * 0.30f - 2755);
} else if (gz < 80000) {// 35 5505
ss = (int) (gz * 0.35f - 5505);
} else {
ss = (int) (gz * 0.45f - 13505);
}
System.out.println("您所有要交付的税务:" + ss + "元");
System.out.println("剩下的工资:" + (gz + 3500 - ss) + "元");
} else {
System.out.println("您的工资还不在个人所得税之内,加油!");
}
}
}
注明:凯哥学堂课堂笔记
欢迎光临 凯哥学堂 (http://kaige123.com/)
Powered by Discuz! X3.3