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);
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With