第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

【6-8完善練習(xí)】生成3個(gè)不重復(fù)的1000以內(nèi)的隨機(jī)正整數(shù)作為學(xué)生Id

package?com.imooc.collection;

import?java.util.ArrayList;
import?java.util.Collections;
import?java.util.List;
import?java.util.Random;

public?class?CollectionsTest?{
public?List<String>?randomList(){
????List<String>?strList=new?ArrayList<String>();;
????String?str;
????Random?random=new?Random();
????for(int?i=0;i<3;i++){

????????do{str=random.nextInt(999)+1+"";
????????}while(strList.contains(str));
????????strList.add(str);
????}
????return?strList;
}

public?void?testSort3(){
????List<Student>?studentList=new?ArrayList<Student>();
????List<String>?strList=randomList();
????studentList.add(new?Student(strList.get(0),"Mike"));
????studentList.add(new?Student(strList.get(1),"Angela"));
????studentList.add(new?Student(strList.get(2),"Lucy"));
????System.out.println("------------排序前------------");
????for?(Student?student:studentList)?{
????????System.out.println("學(xué)生:"+student.getStudent_id()+":"+student.getStudent_name());
????}
????Collections.sort(studentList);
????System.out.println("------------排序后------------");
????for?(Student?student:studentList)?{
????????System.out.println("學(xué)生:"+student.getStudent_id()+":"+student.getStudent_name());
????}
????System.out.println("------------按照姓名排序前------------");
????for?(Student?student:studentList)?{
????????System.out.println("學(xué)生:"+student.getStudent_id()+":"+student.getStudent_name());
????}
????Collections.sort(studentList,new?StudentComparator());
????System.out.println("------------按照姓名排序后------------");
????for?(Student?student:studentList)?{
????????System.out.println("學(xué)生:"+student.getStudent_id()+":"+student.getStudent_name());
????}
}
public?static?void?main(String[]?args)?{
????CollectionsTest?collectionsTest=new?CollectionsTest();
?????collectionsTest.testSort3();



????}
}
/*
Student類
*/
package?com.imooc.collection;

import?java.util.HashSet;
import?java.util.Objects;
import?java.util.Set;

public?class?Student?implements?Comparable<Student>?{
????private?String?student_id;
????private?String?student_name;
????public?Set<Course>?student_course;

????public?String?getStudent_id(){
????????return?this.student_id;
????}
????public?void?setStudent_id(String?student_id){
????????this.student_id=student_id;
????}

????public?String?getStudent_name()?{
????????return?this.student_name;
????}
????public?void?setStudent_name(String?student_name)?{
????????this.student_name?=?student_name;
????}

????public?Student(){

????}

????@Override
????public?boolean?equals(Object?o)?{
????????if?(this?==?o)?return?true;
????????if?(o?==?null?||?getClass()?!=?o.getClass())?return?false;
????????Student?student?=?(Student)?o;
????????return?Objects.equals(student_name,?student.student_name);
????}

????@Override
????public?int?hashCode()?{
????????return?Objects.hash(student_name);
????}



????public?Student(String?id,?String?name){
????????this.student_id=id;
????????this.student_name=name;
????????this.student_course=new?HashSet<Course>();
????}

????@Override
????public?int?compareTo(Student?o)?{
????????return?this.student_id.compareTo(o.student_id);
????}
}


正在回答

1 回答

你這個(gè)寫得有些復(fù)雜了吧,用時(shí)間對(duì)象可以不?

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

【6-8完善練習(xí)】生成3個(gè)不重復(fù)的1000以內(nèi)的隨機(jī)正整數(shù)作為學(xué)生Id

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)