1 PackageCom.java7;2 //demonstrate the relational and logical operators.3 Public classRellogops {4 Public Static voidMain (string[] args) {5 intI, J;6 BooleanB1, B2;7 8i = 10;9j = 11;Ten One if(I < J) System.out.println ("I < J"); A if(I <= J) System.out.println ("I <= J"); - if(I! = j) SYSTEM.OUT.PRINTLN ("I! = j"); - if(i = = j) System.out.println ("i = = j");//This won ' t execute the if(I >= J) System.out.println ("I >= J");//This won ' t execute - if(i > J) System.out.println ("I > J");//This won ' t execute - -B1 =true; +B2 =false; - if(B1 & B2) System.out.println ("B1 & B2 is true");//false + if(! (B1 & B2)) SYSTEM.OUT.PRINTLN ("!" ( B1 & B2) is true ");//true:!true = false;!false = True (reverse; As long as there is a true) A if(B1 | b2) System.out.println ("B1 | B2 is true ");//True:true or False returns True (as long as there is a true) at if(B1 ^ b2) System.out.println ("B1 ^ B2 is true");//True:true xor False Returns True (with and only one true) - - System.out.println (); - -B1 =false; -B2 =true; in if(B1 & B2) System.out.println ("B1 & B2 is true");//false - if(! (B1 & B2)) SYSTEM.OUT.PRINTLN ("!" ( B1 & B2) is true ");//true:!false = true;!true = False (reverse; As long as there is a true) to if(B1 | b2) System.out.println ("B1 | B2 is true ");//True:false or True returns Ture (as long as there is a true) + if(B1 ^ b2) System.out.println ("B1 ^ B2 is true");//True:false xor True returns True (with and only one true) - the System.out.println (); * $B1 =true;Panax NotoginsengB2 =true; - if(B1 & B2) System.out.println ("B1 & B2 is true");//true the if(! (B1 & B2)) SYSTEM.OUT.PRINTLN ("!" ( B1 & B2) is true ");//false:!true = false;!true = False (reverse; As long as there is a true) + if(B1 | b2) System.out.println ("B1 | B2 is true ");//True:true or True returns True (as long as there is a true) A if(B1 ^ b2) System.out.println ("B1 ^ B2 is true");//False:true xor True returns False (with and only one true) the + System.out.println (); - $B1 =false; $B2 =false; - if(B1 & B2) System.out.println ("B1 & B2 is true");//false - if(! (B1 & B2)) SYSTEM.OUT.PRINTLN ("!" ( B1 & B2) is true ");//true:!false = true;!false = True (reverse; As long as there is a true) the if(B1 | b2) System.out.println ("B1 | B2 is true ");//False:false or False returns False (as long as there is a true) - if(B1 ^ b2) System.out.println ("B1 ^ B2 is true");//False:false xor False returns False (with and only one true)Wuyi } the}
Solving problems. Logical operators. &,!, |, ^