字符串排序
来源:互联网 发布:沉默的螺旋理论 知乎 编辑:程序博客网 时间:2024/06/03 19:21
public static void main(String[] args) {
String temp = null;
String[] s = new String[5];
s[0] = "china".toLowerCase();
s[1] = "apple".toLowerCase();
s[2] = "MONEY".toLowerCase();
s[3] = "BOOk".toLowerCase();
s[4] = "yeah".toLowerCase();
for(int i=0; i<s.length; i++) {
for(int j=i+1; j<s.length; j++) {
if(compare(s[i], s[j]) == false) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
for(int i=0; i<s.length; i++) {
System.out.println(s[i]);
}
}
static boolean compare(String s1, String s2) {
boolean result = true;
for(int i=0; i<s1.length() && i<s2.length(); 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;
}
}
String temp = null;
String[] s = new String[5];
s[0] = "china".toLowerCase();
s[1] = "apple".toLowerCase();
s[2] = "MONEY".toLowerCase();
s[3] = "BOOk".toLowerCase();
s[4] = "yeah".toLowerCase();
for(int i=0; i<s.length; i++) {
for(int j=i+1; j<s.length; j++) {
if(compare(s[i], s[j]) == false) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
for(int i=0; i<s.length; i++) {
System.out.println(s[i]);
}
}
static boolean compare(String s1, String s2) {
boolean result = true;
for(int i=0; i<s1.length() && i<s2.length(); 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 0
- 字符串排序
- 字符串排序
- 字符串排序
- 字符串排序
- 字符串排序
- 字符串排序。
- 字符串排序
- 字符串排序
- 字符串排序
- 字符串排序
- 字符串排序
- 字符串排序
- 字符串排序
- 字符串排序
- 字符串排序
- 字符串排序
- 字符串排序
- 排序字符串
- 一个字符串中最长的不重复子串
- 设计模式之解释器模式(Interpreter)摘录
- Apache Shiro 使用手册 链接目录整理
- 找出字符串的最长子串,要求子串的所有字符相同,如:"abcdeeefgh"结果是"eee"
- ecshop 二次开发
- 字符串排序
- C++的static关键字
- 题目:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。
- 浅谈设计模式
- HDU--Max sum(DP)
- Single Number II
- 【HTML、JAVASCRIPT、CSS】3、Javascript基本概念
- 求一个字符串中大小写个数
- 打印一个目录结构