gpt4 book ai didi

java - 二元运算符的错误操作数类型

转载 作者:搜寻专家 更新时间:2023-11-01 01:45:17 24 4
gpt4 key购买 nike

我是编程新手,不明白为什么第十行的 || 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 中,|| 的两边都必须有 boolean 值。而且,one % 6one % 17 都不是 boolean 值。但是,one % 6 != 0one % 17 != 0 是。

关于java - 二元运算符的错误操作数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12739481/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com