集册 Java实例教程 逻辑运算符。

逻辑运算符。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

639
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
逻辑运算符。

public class Main 

{

   public static void main(String[] args)/* 来自 n o w j a   v  a . c o m - 时  代  Java*/

   {

      // create truth table for && (conditional AND) operator

      System.out.printf("%s%n%s: %b%n%s: %b%n%s: %b%n%s: %b%n%n",

         "Conditional AND (&&)", "false && false", (false && false),

         "false && true", (false && true), 

         "true && false", (true && false),

         "true && true", (true && true));


      // create truth table for || (conditional OR) operator

      System.out.printf("%s%n%s: %b%n%s: %b%n%s: %b%n%s: %b%n%n",

         "Conditional OR (||)", "false || false", (false || false),

         "false || true", (false || true),

         "true || false", (true || false),
         /** 
          来自 时代Java - nowjava.com**/

         "true || true", (true || true));


      // create truth table for & (boolean logical AND) operator

      System.out.printf("%s%n%s: %b%n%s: %b%n%s: %b%n%s: %b%n%n",

         "Boolean logical AND (&)", "false & false", (false & false),

         "false & true", (false & true),

         "true & false", (true & false),

         "true & true", (true & true));


      // create truth table for | (boolean logical inclusive OR) operator

      System.out.printf("%s%n%s: %b%n%s: %b%n%s: %b%n%s: %b%n%n",

         "Boolean logical inclusive OR (|)",

         "false | false", (false | false),

         "false | true", (false | true),

         "true | false", (true | false),

         "true | true", (true | true));


      // create truth table for ^ (boolean logical exclusive OR) operator

      System.out.printf("%s%n%s: %b%n%s: %b%n%s: %b%n%s: %b%n%n",

         "Boolean logical exclusive OR (^)", 

         "false ^ false", (false ^ false),

         
展开阅读全文