import java.util.*;
public class Test4
{
public void fun(){
double a= 0;
double b = 0;
double tax = 0;
Scanner sc=new Scanner(System.in);
System.out.println("请输入本月工资:");
a=sc.nextDouble();
if(a<=1600)
System.out.println("不需缴纳税款");
else
b=a-1600;
if(b<=500)
tax=b*0.05;
else if(b<=2000)
tax=25+(b-500)*0.1;
else if(b<=5000)
tax=175+(b-2000)*0.15;
else if(b<=20000)
tax=625+(b-5000)*0.2;
else if(b<=40000)
tax=3625+(b-20000)*0.25;
else if(b<=60000)
tax=8625+(b-40000)*0.3;
else if(b<=80000)
tax=14625+(b-60000)*0.35;
else if(b<=100000)
tax=21625+(b-80000)*0.4;
else
tax=29625+(b-100000)*0.45;
System.out.println("个人所得税为:"+tax);
}
public static void main(String[] args){
Test4 t = new Test4();
t.fun();
}
}
我喜欢这么调
import java.util.*;
public class Test4
{
public static void main(String args[]){
double a,b = 0,tax;
Scanner sc=new Scanner(System.in);
System.out.println("请输入本月工资:");
a=sc.nextDouble();
if(a<=1600)
System.out.println("不需缴纳税款");
else
b=a-1600;
if(b<=500)
tax=b*0.05;
else if(b<=2000)
tax=25+(b-500)*0.1;
else if(b<=5000)
tax=175+(b-2000)*0.15;
else if(b<=20000)
tax=625+(b-5000)*0.2;
else if(b<=40000)
tax=3625+(b-20000)*0.25;
else if(b<=60000)
tax=8625+(b-40000)*0.3;
else if(b<=80000)
tax=14625+(b-60000)*0.35;
else if(b<=100000)
tax=21625+(b-80000)*0.4;
else
tax=29625+(b-100000)*0.45;
System.out.println("个人所得税为:"+tax);
}
}
这样就ok了.你写的东西不放在方法里怎么执行啊?还有b要给初始值。
兄弟,你都不把代码放到main方法里,肯定报错呀,
double a,b,tax;这几个变量最好付初值!