OneCompiler

LogicalOperators

1646

class logicalOperators{
public static void main(String[] args){
int n,d;
n = 20;
d = 4;
if(d!= 0 && (n % d)==0)
System.out.println(d + " is a factor of " + n);
d=0;// now,set d to zero
//Since d is zero, the second operand is not evaluated.
if(d!=0 && (n % d)==0)
System.out.println(d + " is a factor of " + n);
/*Now,try the same things without short-circuit operator.
This will cause a divide-by-zero error.
*/
if(d!=0 &&(n % d)==0)
System.out.println(d +" is a factor of " + n);
}
}