public static void main(String[] args) {
int N=5;
String temp = null;
String[] s = new String[N];
s[0] = "matter";
s[1] = "state";
s[2] = "solid";
s[3] = "liquid";
s[4] = "gas";
for(int i=0; i
for(int j=i+1; j
if(compare(s[i], s[j]) == false) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
for(int i=0; i
System.out.println(s[i]);
}
}
static boolean compare(String s1, String s2) {
boolean result = true;
for(int i=0; i
if(s1.charAt(i) > s2.charAt(i)) {
result = false;
break;
} else if(s1.charAt(i) <s2.charAt(i)) {
result = true;
break;
} else {
if(s1.length() < s2.length()) {
result = true;
} else {
result = false;
}
}
}
return result;
}
}
请问这个是如何比较的,思路是什么,步骤表示什么意思,万分感谢!
请问这个是如何比较的,思路是什么,步骤表示什么意思,万分感谢!
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
threenewbee 2016-08-25 08:59关注对两个字符串逐个字符比较ascii,如果第一个比第二个大,返回false,第二个比第一个大,返回true,两个相等,比字符串的长度,如果第一个字符串短,返回true,否则返回false。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报