java基礎(五章)

來源:互聯網
上載者:User

標籤:好處   斷點   href   啟動   follow   string   --   筆記本   als   

java基礎(五章)

一、        調試

步驟1:設定斷點(不能在空白處設定斷點)

步驟2:啟動調試

步驟3:調試代碼(F6單步跳過)筆記本Fn+F6(F5)

步驟4:結束調試

掌握調試的好處?

l  很清晰的看到,代碼執行的順序

l  快速定位到異常代碼出現的位置,並協助修改或改進代碼

二、     while迴圈

1、迴圈的優點?

           減少重複代碼的編寫;程式會更加的簡潔

2、文法

           while(運算式){

// 1、運算式是【迴圈條件】,結果必須是boolean類型

                  //2、{}中的代碼,即【迴圈操作(體)】

                  //3、【迭代部分】更改迴圈條件,結束迴圈

           }

3、特點:先判斷,再執行

4、while迴圈有2種常見的方式

           方式1:

public class WhileDemo {
  public static void main(String[] args) {
    String answer;
    Scanner input = new Scanner (System.in);
    System.out.print("合格了嗎?(y/n):");
    answer = input.next();
    while(!"y".equals(answer)){
        System.out.println("上午閱讀材料!");
        System.out.println("下午上級編程!\n");
        System.out.println("合格了嗎?(y/n:)");
        answer = input.next();
      }
     System.out.println("完成學習任務!");
   }

}

                  while(1、迴圈條件: 判斷字串是否相等){

                                //2、迴圈操作

                                //3、再次接收鍵盤中的字串,更改迴圈條件,來結束迴圈

}

           方式2:

           public static void main (String[] args) {

               int count = 1;

              while(count <= 50) {

            System.out.println("列印第" +count+ "份試卷");

          count++;

        }

    }

                         while(1、迴圈條件: int變數結合關係運算子做比較){

                                //2、迴圈操作

//3、迭代部分,int變數++或--,來更改迴圈條件,結束迴圈操作

                         }

三、do….while迴圈

1、            適用場合    :先迴圈1次,根據條件判斷後,再迴圈

2、            文法

do{

       //2、迴圈體(迴圈操作)

       //3、更改迴圈條件

}while(條件) ;   //1、迴圈條件

    

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.