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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                **第一題:** 輸入一行字符,分別統計出其英文字母、空格、數字和其它字符的個數。 提示: 對比char字符在ASK碼的范圍,就可以確定它符號的類別 char字符ASK碼的范圍 * 數字0到9:?48~57 * 字母A到Z:65到90?a到z:97到122 * 空格是32 如: ``` char a = 'a'; 97<= a <=122 ``` ~~~ public class Demo { public static void main(String[] args) { getCharNum(""); } public static void getCharNum(String str) { //數字字符總數 int num = 0; //字母字符總數 int eng = 0; //空格總數 int space = 0; //其他字符總數 int other = 0; if(str != null) { //首先將string類型的字符串,變為一個個的char數組 char[] charArray = str.toCharArray(); for(int i = 0; i < charArray.length; i++) { char c = charArray[i]; //對遍歷出來的char值做判斷 if (c >= 48 && c <= 57) {//字符是數字 num++; } else if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) {//字符是字母 eng++; } else if (c == 32) {//字符是空格 space++; } else { other++;//其他 } } System.out.println("數字有:" + num + "個," + "字母有:" + eng + "個," + "空格有:" + space + "個," + "其他字符有:" + other + "個"); } else { System.out.println("輸入字符不合法"); } } } ~~~ **第二題** 要求寫一個秒表類(StopWatch),該秒表類該類在系統中只能有存在一個實例。并且存在star方法,可以用于開始計時,并且輸出開始時間,同時存在stop方法用于停止計時,輸出結束時間,要求秒表可以存儲以毫秒為單位十個計時任務 ~~~ public class StopWatch { private static StopWatch stopWatch = new StopWatch(); private StopWatch() { } public static StopWatch getInstance() { return stopWatch; } private long startTime; private List<Long> record = new ArrayList<Long>(); public List<Long> getRecord() { return record; } public void start() { Date date = new Date(); this.startTime = date.getTime(); } public void end() { if(startTime == 0) { System.out.println("未曾開始"); } else { Date date = new Date(); long endTime = date.getTime(); long time = endTime - startTime; if(record.size() >= 10) { record.remove(0); record.add(time); } else { record.add(time); } this.startTime = 0; } } } public class Demo { public static void main(String[] args) throws InterruptedException { StopWatch stopWatch = StopWatch.getInstance(); //第一次計時 stopWatch.start(); System.out.println(stopWatch.getRecord()); //讓程序休息30毫秒 Thread.sleep(30); stopWatch.end(); System.out.println(stopWatch.getRecord()); //第二次計時 stopWatch.start(); //讓程序休息10毫秒 Thread.sleep(10); stopWatch.end(); System.out.println(stopWatch.getRecord()); stopWatch.start(); Thread.sleep(3); stopWatch.end(); System.out.println(stopWatch.getRecord()); stopWatch.start(); Thread.sleep(4); stopWatch.end(); System.out.println(stopWatch.getRecord()); stopWatch.start(); Thread.sleep(5); stopWatch.end(); System.out.println(stopWatch.getRecord()); stopWatch.start(); Thread.sleep(6); stopWatch.end(); System.out.println(stopWatch.getRecord()); stopWatch.start(); Thread.sleep(7); stopWatch.end(); System.out.println(stopWatch.getRecord()); stopWatch.start(); Thread.sleep(8); stopWatch.end(); System.out.println(stopWatch.getRecord()); stopWatch.start(); Thread.sleep(9); stopWatch.end(); System.out.println(stopWatch.getRecord()); stopWatch.start(); Thread.sleep(10); stopWatch.end(); System.out.println(stopWatch.getRecord()); stopWatch.start(); Thread.sleep(11); stopWatch.end(); System.out.println(stopWatch.getRecord()); stopWatch.start(); Thread.sleep(12); stopWatch.end(); System.out.println(stopWatch.getRecord()); } } ~~~ # 綜合案例(面向對象) ## 場景案例: 學校新開一門專業,叫做計算機科學與應用,專業編號J0001,學制年限為4年。 現有三名學生如下表所示,加入該專業學習,要求采用Java面向對象的思維描述該場景: | 姓名 | 學號 | 性別 | 年齡 | | --- | --- | --- | --- | | 張三 | S01 | 男 | 18歲 | | 李四 | S02 | 女 | 17歲 | | 王五 | S03 | 男 | 18歲 | ## 實現效果 ![](https://img.kancloud.cn/71/3d/713dfa7a3fc7174f072e6fb00f76dc9b_1011x486.png) ## 案例分析 1. 本場景中共存在幾個對象?各自的特征是什么? 2. 我們又可以針對這幾個對象抽象歸納出幾個類出來 ## 代碼實現
                  <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>

                              哎呀哎呀视频在线观看