20161028问题解析请点击今日问题下方的“【Java每日一题】20161031”查看
今日问题:
请问主程序输出结果是?(点击以下“【Java每日一题】20161031”查看20161028问题解析)
题目原发布于公众号、简书:[url=http://mp.weixin.qq.com/s?__biz=MzI4ODEyMTgwMA==&mid=2650163227&idx=1&sn=5c2ceed322423ee63306525d129f839d&chksm=f3c1debcc4b657aa0f1b7a2ebd3b45d226a1089d6a23575aedc28e63dc0e98a5201eeec9d459&scene=0#wechat_redirect]【Java每日一题】20161031[/url],[url=http://www.jianshu.com/p/b4a35a5a8bf7]【Java每日一题】20161031[/url]
每日一题最新将在公众号发布,欢迎订阅,交流进步
[img]https://img-blog.csdn.net/20161017115128961?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast[/img]
package Oct2016;
import java.util.SortedSet;
import java.util.TreeSet;
public class Ques1031 {
public static void main(String[] args) {
SortedSet<People> set = new TreeSet<People>();
set.add(new People(170));
set.add(new People(165));
for(People people : set){
System.out.println("身高:"+people.getHeight());
}
System.out.println();
// 将身高矮的人变高
set.first().setHeight(175); //之前排在第一位的人就是最矮的
for(People people : set){
System.out.println("身高:"+people.getHeight());
}
}
}
class People implements Comparable<People>{
private int height;
public People(int height) {
super();
this.height = height;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
@Override
public int compareTo(People p) {
// 按身高从矮到高排序
return height - p.height;
}
}
今日问题:
请问主程序输出结果是?(点击以下“【Java每日一题】20161031”查看20161028问题解析)
题目原发布于公众号、简书:[url=http://mp.weixin.qq.com/s?__biz=MzI4ODEyMTgwMA==&mid=2650163227&idx=1&sn=5c2ceed322423ee63306525d129f839d&chksm=f3c1debcc4b657aa0f1b7a2ebd3b45d226a1089d6a23575aedc28e63dc0e98a5201eeec9d459&scene=0#wechat_redirect]【Java每日一题】20161031[/url],[url=http://www.jianshu.com/p/b4a35a5a8bf7]【Java每日一题】20161031[/url]
每日一题最新将在公众号发布,欢迎订阅,交流进步
[img]https://img-blog.csdn.net/20161017115128961?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast[/img]