【问题标题】:Bad operand types for binary operator二元运算符的错误操作数类型
【发布时间】:2012-10-05 04:27:13
【问题描述】:

我是编程新手,我不明白为什么第十行中的|| while (one%6||one%17){ 被认为是二元运算符的坏操作数类型。如果有人能帮助我理解这一点,将不胜感激。

import java.util.Scanner;

public class DivisibleBy6or17 {
    public static void main(String[] args){             
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Value: ");
        int one = in.nextInt();
        int sum=0;

        while (one%6||one%17){
            System.out.print("Enter Value: ");
            sum=+1;
        }
        System.out.print("Numbers read: " + sum);
    }
}

【问题讨论】:

  • 这是Java,不是C。你需要将模数的结果与0进行比较。

标签: java


【解决方案1】:

在 Java 中,|| 的两边都必须有布尔值。而且,one % 6one % 17 都不是布尔值。但是,one % 6 != 0one % 17 != 0 是。

【讨论】:

    猜你喜欢
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    相关资源
    最近更新 更多