éè¦10个å¦çå°±å¨å建5个å¦çï¼ç¶åmapè¿å»ãææå¾åäºã
package package2;
import java.util.HashMap;
import java.util.Map;
public class Test {
public static void main(String[] args) {
Map<Integer, Student> map = new HashMap<Integer, Student>();
Student stu1 = new Student();
stu1.setName("第ä¸ä¸ªå¦ç");
stu1.setHeigth(180);
Student stu2 = new Student();
stu2.setName("第äºä¸ªå¦ç");
stu2.setHeigth(170);
Student stu3 = new Student();
stu3.setName("第ä¸ä¸ªå¦ç");
stu3.setHeigth(185);
Student stu4 = new Student();
stu4.setName("第å个å¦ç");
stu4.setHeigth(187);
Student stu5 = new Student();
stu5.setName("第äºä¸ªå¦ç");
stu5.setHeigth(175);
map.put(stu1.getHeigth(), stu1);
map.put(stu2.getHeigth(), stu2);
map.put(stu3.getHeigth(), stu3);
map.put(stu4.getHeigth(), stu4);
map.put(stu5.getHeigth(), stu5);
int[] array = { stu1.getHeigth(), stu2.getHeigth(), stu3.getHeigth(),
stu4.getHeigth(), stu5.getHeigth() };
int a;
for (int i = 0; i < array.length; i++) {
for (int j = 0 + i; j < array.length; j++) {
if (array[i] < array[j]) {
a = array[i];
array[i] = array[j];
array[j] = a;
}
}
}
int c = array[0];
Student s = map.get(c);
System.out.println(s.getName() + "身é«æé«ä¸ºï¼" + c + "åç±³ã");
}
}
温馨提示:内容为网友见解,仅供参考