<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國際加速解決方案。 廣告
                # 2018-03-21 周測試題 **機測:** 在 Eclipse 中新建項目,將以下試題完成,時間 60 min 1、將字符串「a-b-c-d-e-f」按 「-」 切割,找到 「c」字符,替換為大寫,然后**倒序**輸出 「f-e-d-C-b-a」。 ~~~ package com.ntqn.test.title; public class Test1 { public static void main(String[] args) { String str = "a-b-c-d-e-f"; String[] strs = str.split("-"); // 循環遍歷,小寫字母變大寫 for (int i = 0; i < strs.length; i++) { String s = strs[i]; if (s.equals("c")) { strs[i] = s.toUpperCase(); } } String temp = ""; for (int i = strs.length - 1; i >= 0; i--) { temp += strs[i] + "-"; } // 去除最后一個短橫 System.out.println(temp.substring(0, temp.length()-1)); } } ~~~ 2、定義學生類(包含學號、姓名、年齡),將你所在小組組員添加到一個集合中,并按**學號排序**后輸出。 ~~~ package com.ntqn.test.title; public class Student implements Comparable<Student> { private int code; private String name; private int age; public int getCode() { return code; } public void setCode(int code) { this.code = code; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Student(int code, String name, int age) { super(); this.code = code; this.name = name; this.age = age; } @Override public int compareTo(Student o) { int flag; if (this.code > o.code) { flag = -1; } else if (this.code == o.code) { flag = 0; } else { flag = 1; } return flag; } @Override public String toString() { return "Student [code=" + code + ", name=" + name + ", age=" + age + "]"; } } ~~~ ~~~ package com.ntqn.test.title; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Test2 { public static void main(String[] args) { List<Student> teams = new ArrayList<Student>(); // 新建學生對象 Student stu1 = new Student(1, "Tom", 15); Student stu2 = new Student(3, "Jack", 13); Student stu3 = new Student(2, "Helen", 18); Student stu4 = new Student(4, "May", 12); // 向集合添加學生對象 teams.add(stu1); teams.add(stu2); teams.add(stu3); teams.add(stu4); // 按學號倒敘排列 Collections.sort(teams); // 遍歷學生 for (Student stu : teams) { System.out.println(stu); } } } ~~~ 3、緊接第二題,用**單例設計**一個服務類,并定義一個方法,可以**隨機抽取**集合中的某個學生對象,并打印輸出。 ~~~ package com.ntqn.test.title; import java.util.List; public class Service { private static Service service = new Service(); private Service() { } public static Service getInstance() { return service; } public Student randomStu(List<Student> stus) { if (null != stus && !stus.isEmpty()) { return stus.get((int)(Math.random() * stus.size())); } else { return null; } } } ~~~ ~~~ package com.ntqn.test.title; import java.util.ArrayList; import java.util.List; public class Test3 { public static void main(String[] args) { List<Student> teams = new ArrayList<Student>(); Student stu1 = new Student(1, "Tom", 15); Student stu2 = new Student(3, "Jack", 13); Student stu3 = new Student(2, "Helen", 18); Student stu4 = new Student(4, "May", 12); teams.add(stu1); teams.add(stu2); teams.add(stu3); teams.add(stu4); // 通過靜態方法獲取對象 Service service = Service.getInstance(); System.out.println("==========隨機抽取學生============="); Student randomStu = service.randomStu(teams); System.out.println(randomStu); } } ~~~
                  <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>

                              哎呀哎呀视频在线观看