CHAMP3333 CHAMP3333 - 1 year ago 285
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++) {
for(i=0;i<number.length;i++) {
if((number[i]>100) && (number[i]<200) && (number[i]/7)) {
System.out.println("Sum =" +sum);

Answer Source

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


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download