java筆記8之選擇結構IF

來源:互聯網
上載者:User

標籤:bool   控制   sys   大於   print   比較   沒有   div   運算式   

注意1

        A比較運算式無論簡單還是複雜,結果必須是boolean類型
        B:if語句控制的語句體如果是一條語句,大括弧可以省略;
          如果是多條語句,就不能省略。建議永遠不要省略。
        C:一般來說:有左大括弧就沒有分號,有分號就沒有左大括弧

 1 class IfDemo2 { 2     public static void main(String[] args) { 3         int x = 10; 4          5         if(x == 10) { 6             System.out.println("x等於10"); 7         } 8          9         if((x > 5) || (x == 10)) {10             System.out.println("x大於或者等於10");11         }12         System.out.println("-------------------");13         14         int a = 100;15         16         /*17         if(a == 100) {18             System.out.println("a的值是100");19         }20         */21         22         if(a != 100) {23             System.out.println("a的值是100");24             System.out.println("over");25         }26         System.out.println("-------------------");27         28         int b = 100;29         if(b != 100);  //這裡其實是有語句體的,只不過是空語句體。30         31         //代碼塊32         {33             System.out.println("b的值是100");34             System.out.println("over");35         }36     }37 }

 

java筆記8之選擇結構IF

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.