<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 條件語句 if單一條件 if..else二選一(三元運算符) if..else if...多選一 switch ``` public static void main(String[] args) { // switch Scanner scan = new Scanner(System.in); System.out.println("請輸入:"); int num = scan.nextInt(); // switch參數只能放 byte short int char switch(num) { // case num:num不能重復 case 1: System.out.println("查詢話費"); break; case 2: System.out.println("人工服務"); break; case 3: System.out.println("業務辦理"); break; case 5: case 4: case 6: System.out.println("無此業務"); break; default: System.out.println("謝謝再見!"); } } ``` ### 循環結構 while循環 ``` int num = 6; while(num < 5) { System.out.println(num); num++; } System.out.println("結束"); ``` ``` // 死循環--常用 while(true) { sum = sum + num; if(sum > 1200) { break;// 終止循環--跳出(結束)循環 } num++; } ``` do..while循環:至少執行一次 ``` public static void main(String[] args) { // do...while // 輸出1-5 int num = 6; do { System.out.println(num); num++; }while(num <= 5); // while和do..while有什么區別:do..while至少執行一次 } ``` for循環 ``` for(int num = 1;num <= 5;num++) { System.out.println(num); } ``` ### continue與break continue:跳過本次循環,執行下次循環 break:終止(當前)循環 ### 循環嵌套 直角三角形 ``` Scanner scan = new Scanner(System.in); System.out.println("請輸入:"); int i = scan.nextInt(); // 外層循環控制執行幾次換行 for(int j = 1;j <= i;j++) { // 內層循環控制畫幾次* for(int k = 1;k <= j;k++) { System.out.print("*"); } // 換行 System.out.println(); } ``` #### 必做題 1.求1!+2!+3!+4!+...10! ``` public class Practice2 { public static void main(String[] args) { int sum = 0; int cj = 1; for(int i = 1;i < 11;i++) { cj = cj * i; sum = sum + cj; } System.out.println(sum); } } ``` 2.一球從100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地時,共經過多少米?第10次反彈多高? ``` public class Practice4 { public static void main(String[] args) { double height = 100; double dis = height/2; for(int i = 2;i <= 10;i++) { height = height + dis * 2; dis = dis / 2; } System.out.println(height); System.out.println(dis); } } ``` 3.打印出所有的"水仙花數",所謂"水仙花數"是指一個三位數,其各位數字立方和等于該數本身。 ``` public class Practice5 { public static void main(String[] args) { for(int i = 100;i < 1000;i++) { int b = i/100; int s = i%100/10; int g = i%10; if(b*b*b+s*s*s+g*g*g == i) { System.out.println(i); } } } } ```
                  <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>

                              哎呀哎呀视频在线观看