double value cannot be converted to boolean

huangapple go评论67阅读模式
英文:

double value cannot be converted to boolean

问题

I'm just not sure why I'm getting this error, I would appreciate it if you could help me out to find the error. here is the code,

import java.util.Scanner;

public class FirstSelectionProgram {

    public static void main(String[] args) {

        Scanner key = new Scanner(System.in);

        double spent;

        System.out.println("Please Enter The Amount That You Have Spent: ");
        spent = key.nextDouble();

        if (0.01 <= spent && spent <= 40) {
            System.out.println("you will receive 20% off");
        } else {
            System.out.println("you won't receive anything");
        }
    }
}

我只翻译代码部分。

英文:

I'm just not sure why I'm getting this error, I would appreciate it if you could help me out to find the error. here is the code,

import java.util.Scanner;

public class FirstSelectionProgram {

    public static void main(String[] args) {

        Scanner key=new Scanner(System.in);

        double spent;

        System.out.println(&quot;Please Enter The Amount That You Have Spent: &quot;);
        spent= key.nextDouble();

        if (0.01=&lt;spent &amp;&amp; spent=&lt;40)
        {
            System.out.println(&quot;you will receive 20% off&quot;);
        }
        else
        {
            System.out.println(&quot;you won&#39;t receive anything&quot;);
        }
    }
}

答案1

得分: 1

"Instead of doing if (0.01 &lt;= spent &amp;&amp; spent &lt;= 40) try if (0.01 &lt;= spent &amp;&amp; spent &lt;= 40)"

英文:

Instead of doing if (0.01=&lt;spent &amp;&amp; spent=&lt;40) try if (0.01 &lt;= spent &amp;&amp; spent &lt;= 40)

huangapple
  • 本文由 发表于 2020年8月10日 22:18:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/63342039.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定