CHAMP3333 CHAMP3333 - 5 months ago 93
Java Question

What does the error " bad operand types for binary operator '&&' " mean in java program?

I get in next code:

class Divisible {

public static void main(String args[]) {
int number[]=new int[200];
int i,sum=0;
for(i=0;i<number.length;i++) {
number[i]=i;
}
for(i=0;i<number.length;i++) {
if((number[i]>100) && (number[i]<200) && (number[i]/7)) {
sum=sum+number[i];
}
}
System.out.println("Sum =" +sum);
}
}

Answer

It is quite clear - && is a binary operator and you need to use a boolean operand for it.

Here:

if((number[i]>100) && (number[i]<200) && (number[i]/7))

(number[i]/7) is a number, and it does not qualify to be an operand of && operator.

Comments