62,616
社区成员
发帖
与我相关
我的任务
分享
public class Test01 {
public static void main(String[] args) {
char ch[] = {'j','K','a','A','f','F'};
System.out.println("before sorting, array=" + Arrays.toString(ch));
for (int i = 0; i < ch.length; i++) {
for (int j = 0; j < ch.length-1; j++) {
if (lt(ch[i], ch[j])) {
char t = ch[i];
ch[i]=ch[j];
ch[j]=t;
}
}
}
System.out.println("after sorting, array=" + Arrays.toString(ch));
}
private static boolean lt(char c, char d) {
if (c == d - 'A' + 'a') {
return false;
}
if (c - 'A' + 'a' == d) {
return true;
}
return Character.toLowerCase(c) - Character.toLowerCase(d) < 0;
}
}