Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad operand types for binary operator

Tags:

java

I'm new to programming and I don't understand why || in the tenth line while (one%6||one%17){ is considered bad operand types for binary operator. If someone could help me understand this, it would be greatly appreciated.

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);
    }
}
like image 713
user1721929 Avatar asked Feb 18 '23 23:02

user1721929


1 Answers

In Java, you have to have boolean values on both sides of ||. And, neither one % 6 nor one % 17 are boolean. However, one % 6 != 0 and one % 17 != 0 are.

like image 102
Chris Jester-Young Avatar answered Feb 27 '23 10:02

Chris Jester-Young