帮我检查一下这个JAVA程序哪里出错了
解决时间 2021-04-26 21:17
- 提问者网友:别再叽里呱啦
- 2021-04-26 06:21
是用来计算个人所得税的,编译出现一大片的错误,我找了很久都找不出,麻烦各位帮忙看一下,在我的基础上看需要怎么改
import java.util.*;
public class Test4
{
double a,b,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);
}
最佳答案
- 五星知识达人网友:上分大魔王
- 2021-04-26 06:52
你没写进方法,你先写进main方法再编译。b也没初始化。编译出错的信息业贴上来
拿我改的试试
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);
}
}
全部回答
- 1楼网友:爱难随人意
- 2021-04-26 08:31
- 2楼网友:杯酒困英雄
- 2021-04-26 07:17
毛病不少,我简单改了改。自己看看吧。楼上的改法是编译器帮忙改的吧。import java.util.*;public class Main { public static void main(String[] args) { double a, b, 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); } }}
我要举报
大家都在看
推荐资讯