运行税务计划时获取操作数错误

时间:2014-02-15 22:30:11

标签: java

这些是我尝试在下面运行我的程序时得到的错误..不知道如何解决它们..刚刚开始学习java:

C:\Users\Bryce\Desktop\1504\taxable.java:14: error: bad operand types for binary operator '<'
         (salary >= 15000<20000) {
                         ^
  first type:  boolean
  second type: int

C:\Users\Bryce\Desktop\1504\taxable.java:17: error: bad operand types for binary operator '<='
         (salary>=15000<=35000); {
                       ^
  first type:  boolean
  second type: int
2 errors

Process completed.
------------------------------------------------------------------------------------------

代码:

import java.util.*;
public class taxable {
    public static void main (String[] args) {
         Scanner in=new Scanner(System.in);

         System.out.println("Enter your salary:");
         double salary=in.nextDouble();
         double taxDue;
         if (salary < 15000) {
           System.out.println("No tax applicable");
         }
             if (salary >= 15000<20000) {
           taxDue=15000*10/100;
         }
             if (salary>=15000<=35000);
             {
           taxDue=15000*10/100+20000*20/100;
         }
             if (salary > 35000);
         {
               taxDue=(15000*10/100)+(20000*20/100)+(salary-35000)*35/100;
         }
         System.out.printf("The amount of tax due is: " + taxDue + " ");
         double avTaxRate;
         avTaxRate=taxDue/salary*100;
         System.out.printf("The average tax rate: " + taxDue + "%%");
    }
}

2 个答案:

答案 0 :(得分:1)

salary >= 15000<20000不是有效构造,因为salary >= 15000被计算为布尔值,(boolean) < 20000无效。如果要进行多重比较,可以将其分解为多个子句,例如

if (salary >= 15000 && salary < 20000) {
}

有关构建if子句的更多信息,请访问Java tutorials

答案 1 :(得分:0)

一些错误:

  • 表达式salary>=15000<=35000在java中是错误的,我不知道你认为它意味着什么。同样在这里salary>=15000<=35000。也许你想说salary > x && salary <= y
  • 这是合法的,但很可能是错误的if (salary>=15000<=35000); {。您可能希望删除分号,否则括号之间的代码将始终运行,它不是if子句的一部分。
相关问题