1 classdemo04{2 Public Static voidMain (string[] args) {3 //logical Operators4 5 //Example 16System.out.println (true|false&false);7 //result True8 //The priority of,& in the Java language is higher than |9 Ten One //Example 2 A //three-mesh operator: relationship expression? value 1: Value 2; - intA = 10; - intb = 5; the intc = (a>b)? (a=4):(b=5); - System.out.println (a); - System.out.println (b); - System.out.println (c); + //results: 4,5,4 - + A //Example 3 at intA = 10; - Doubleb = 9.5; -System.out.println (a>b?a:b); - //Results: 10.0 - - in //Example 4 -System.out.println (3>2?1:true); to //Results: 1 + /* - This is actually an automatic packing. the 1 has been installed as an integer type * true is loaded as a Boolean type $ Object obj = 3>2?1:true;Panax Notoginseng System.out.println (obj); - */ the + A //Example 5 the Shorts = 1; +s = s + 1;//Error: 1 is of type int, s+1 is int type, then assigned to short type -s + = 1;//correct: The result of the + = operator is the same as the left type after the calculation is completed $ $ - - //Example 6 the intA = 1; -A + = 3.5;Wuyi System.out.println (a); the //Results: 4 - } Wu}
Java interview (1)--Java logical operators