Question #3569

(4) Write a program to perform all the logical operators on the following two variables, a= 10,b=5?

Expert's answer

There are four logical operators - &, &&, | and | |.
| | And && can only be used in logical expressions.





public class Main {




public static void main(String[] args) {

boolean a = true, b = false;

int i = 10, j = 5;




System.out.println("a & b: " + (a&b));

System.out.println("a | b: " + (a|b));

System.out.println("a && b: " + (a&&b));

System.out.println("a || b: " + (a||b));

System.out.println("i & j: " + (i&j));

System.out.println("i | j: " + (i|j));

}

}
LATEST TUTORIALS
APPROVED BY CLIENTS