<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                這一節我學習java語言中的流程控制語句之中的判斷語句. 首先我們看看if語句的不同格式 看下面的代碼 ~~~ class IfDemo { public static void main(String[] args) { //判斷語句 /************************************** if語句的第一種格式: if(條件表達式) { 執行語句; } */ int x = 3; if(x > 1) {//如果沒有大括號,if就只能控制離它最近的那條語句 System.out.println("yes"); } /************************************** if語句的第二種格式: if(條件表達式) { 執行語句; } else//否則 { 執行語句; } */ if(x > 1) { System.out.println("yes"); } else { System.out.println("no"); } int a = 3,b; if(a>1) b = 100; else b = 200; //b = a>1?100:200; //三元運算符就是if else的語句簡寫格式. //簡寫格式什么時候用? //當if else運算后有一個具體結果時,可以簡化寫成三元運算符. System.out.println("b="+b); /***************************************** if語句的第三種格式: if(條件表達式) { 執行語句; } else if(條件表達式) { 執行語句; } ...... else { 執行語句; } 只有一個代碼塊被執行 */ } } ~~~ 從上面的代碼我們看到了三種不同格式的if語句,看到了三元運算符就是if else的語句簡寫格式.并且是當if else運算有一個具體結果時可以互用. 我們再看一下代碼塊的作用吧 ~~~ public static void main(String[] args) { int m = 89;//兩個打印都打印 /* 局部代碼塊可以定義局部變量的生命同期。 */ {//局部代碼塊 int n = 89;//n的作用域是這個代碼塊 System.out.println(m); System.out.println(n); } System.out.println(m); System.out.println(n);//提示找不到變量n,這就說明n的作用域就是上面的代碼塊 } ~~~ 結果: ![](https://box.kancloud.cn/2016-05-18_573c4171010b1.jpg) 從結果看到了代碼塊中變量出了代碼塊就已經被釋放掉了,也就是說代碼塊中定義的局部變量的作用域就是代碼塊. 最后我們看一個if語句的小例子. ~~~ class IfTest2 { public static void main(String[] args) { /* 一年有四季。 春季:3 4 5 夏季:6 7 8 秋季:9 10 11 冬季:12 1 2 根據用戶輸入的月份,給出對應的季節。 */ int month=12; if(month<1 || month>12) System.out.println(month+"月沒有對應的季節"); else if(month>=3 && month<=5) System.out.println(month+"月是春季"); else if(month>=6 && month<=8) System.out.println(month+"月是夏季"); else if(month>=9 && month<=11) System.out.println(month+"月是秋季"); else System.out.println(month+"月是冬季"); if(month==3||month==4||month==5) System.out.println(month+"月是春季"); else if(month==6||month==7||month==8) System.out.println(month+"月是夏季"); else if(month==9||month==10||month==11) System.out.println(month+"月是秋季"); else if(month==12||month==1||month==2) System.out.println(month+"月是冬季"); else System.out.println(month+"月沒有對就的季節"); } } ~~~ 輸出結果兩個都是冬季.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看