Java 基礎 之 邏輯運算

來源:互聯網
上載者:User

標籤:rgs   特性   邏輯   java   ati   ||   and   code   system   

http://www.verejava.com/?id=16992598459515

public class Operation4{    public static void main(String[] args)    {        //邏輯運算        /*            包括:             與&&(and) ,或||(or) 非!             1. && 當操作兩邊都為true時返回結果為true,否則為false             2. || 當操作兩邊都為false時返回結果為false,否則為true;             3. ! 取反,操作為true返回結果false,否則為true        */        System.out.println(true&&false);        System.out.println(false&&true);        System.out.println(false&&false);        System.out.println(true&&true);                System.out.println("---------------");        System.out.println(true||false);        System.out.println(false||true);        System.out.println(true||true);        System.out.println(false||false);        System.out.println("---------------");        System.out.println(!true);        System.out.println(!false);        // ! 是單目運算        //System.out.println(true!false);        System.out.println("----------------");        boolean b=true;        System.out.println(b);        System.out.println(1>2&&(b=3>4));        System.out.println(b);        System.out.println(2>1&&(b=3>4));        System.out.println(b);        /*        注意:            &&的短路特性: 因為程式是從上往下,從左往右執行的,當判斷左邊為false時            &&的返回結果就已經註定是false ,所以後面的判斷電腦就不執行了.        */        System.out.println("--------------");        boolean b1=true;        System.out.println(b1);        System.out.println(2>1||3>4);        System.out.println(2>1||(b1=3>4));        System.out.println(b1);        System.out.println(1>2||(b1=3>4));        System.out.println(b1);        /*        注意:            || 的短路特性:因為程式是從左往右執行,當判斷左邊為true時 返回結果就已經註定是 true, 所以後面的判斷電腦不執行        */    }}

http://www.verejava.com/?id=16992598459515

Java 基礎 之 邏輯運算

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.