需求:鍵盤錄入5個學生資訊(姓名,語文成績,數學成績,英語成績),按照總分從高到低輸出到控制台。分析:1、建立鍵盤錄入物件;
2、建立treeset集合,使用匿名內部類實現comparator介面,重寫compara方法
3、判斷集合中元素的個數,向其中新增元素
4、遍歷集合
class demo_treeset);
while(ts.size()<5)
for(student : s : ts)}}
class student
public student(string name, int chinese, int math, int english)
public int getsum()
public string tostring()
AJPFX關於Collection介面的總結
15collection list arraylist linkedlist a 新增功能 boolean add object obj 把obj這個元素,新增到集合中去 boolean addall collection c 將 c 這個集合中的所有元素,都新增到本集合中來 b 刪除功能 void...
AJPFX關於ArrayList集合容器的操作
1 建立 arraylist mylist new arraylist 代表建立出egg型別的list,新的arraylist物件會建立在堆上 2 加入元素 egg s new egg mylist.add s 此arraylist會產生乙個 盒子 來放egg物件 3 再加入元素 egg b new...
AJPFX關於執行緒建立的方式
建立執行緒的第一種方式 繼承thread 由子類複寫run方法。步驟 1,定義類繼承thread類 2,目的是複寫run方法,將要讓執行緒執行的 都儲存到run方法中 3,通過建立thread類的子類物件,建立執行緒物件 4,呼叫執行緒的start方法,開啟執行緒,並執行run方法。建立執行緒的第二...