日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
如何使用TreeSet集合-創(chuàng)新互聯(lián)

這篇文章將為大家詳細講解有關如何使用TreeSet集合,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。

創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網綜合服務,包含不限于成都網站設計、做網站、海港網絡推廣、小程序定制開發(fā)、海港網絡營銷、海港企業(yè)策劃、海港品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們大的嘉獎;創(chuàng)新互聯(lián)為所有大學生創(chuàng)業(yè)者提供海港建站搭建服務,24小時服務熱線:18982081108,官方網址:www.cdcxhl.com

需求:鍵盤錄入5個學生信息(姓名,語文成績,數學成績,英語成績),按照總分從高到低輸出到控制臺。分析:1、創(chuàng)建鍵盤錄入對象;
          2、創(chuàng)建TreeSet集合,使用匿名內部類實現Comparator接口,重寫compara方法
          3、判斷集合中元素的個數,向其中添加元素
          4、遍歷集合

class Demo_TreeSet{
         public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                System.out.println("請輸入學生成績格式,語文成績,數學成績,英語成績,總成績");
                TreeSet ts = new TreeSet(new Comparator{
                       public int compara( Student s1,Student s2);
                                  int num = s2.getSum() - s1.getSum();
                                  return num == 0 ? 1 : num;
                });
               while(ts.size()<5){
                    String line = sc.nextLine();                                       
                    String[] arr = line.Split(",");
                    int chinese = Integer.paserInt(arr[1]);
                    int math = Integer.paserInt(arr[2]);
                    int  english = Integer.paserInt(arr[3]);
                    ts.add(new Student(arr[0],chinese,math,english));
                }
                for(Student : s : ts){
                      System.out.println(s);
                 }
          }
}
class Student{
    private String name;
    private int chinses;
    private int math;
    private int enlish;

    public Student() {}
    public Student(String name, int chinese, int math, int english) {
                super();
                this.name = name;
                this.chinese = chinese;
                this.math = math;
                this.english = english;
                this.sum = this.chinese + this.math + this.english;
        }
        public int getSum() {
                return sum;
        }
        
        public String toString() {
                return name + "," + chinese + "," + math + "," + english + "," + sum;
        }
}

關于如何使用TreeSet集合就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。


新聞標題:如何使用TreeSet集合-創(chuàng)新互聯(lián)
瀏覽地址:http://www.dlmjj.cn/article/dejgdc.html