如题所述
charçå¼å³ä¸ºå
¶asciiç å¼..å æ¤.代ç å¦ä¸
public class CharsSort {
// æåº,éç¨å泡æåºæ³
public static String sort(String str) {
char chs[] = str.toCharArray();
int size = chs.length;
char temp;
for (int i = 0; i < size; i++) {
for (int j = size - 1; j > i; j--) {
if (chs[j] < chs[j - 1]) {
temp = chs[j];
chs[j] = chs[j - 1];
chs[j - 1] = temp;
}
}
}
return new String(chs);
}
// ç¨åç»è®¡åç±»å符æ°ç®
public static void statistic(String str) {
int countOfNumber = 0;// æ°åçæ°ç®
int countOfLeter = 0;// åæ¯çæ°ç®
int countOfSymbol = 0;// 符å·çæ°ç®
char[] chs = str.toCharArray();
int size = chs.length;
// å¤æå符类å,åç±»ç»è®¡
for (int i = 0; i < size; i++) {
if ((chs[i] < 'z' && chs[i] > 'a')
|| (chs[i] < 'Z' && chs[i] > 'A')) {
countOfLeter++;
} else if (chs[i] < '9' && chs[i] > '0') {
countOfNumber++;
} else {
countOfSymbol++;
}
}
// æå°ç»è®¡ç»æ
System.err.println("å å«åæ¯:" + countOfLeter + "个");
System.err.println("å å«æ°å:" + countOfNumber + "个");
System.err.println("å å«å ¶ä»ç¬¦å·:" + countOfSymbol + "个");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// æµè¯ç»æ
String str = "68765Shfsa*3219(6faylahjyAbo81av)tiA52N<6#6&0_84";
str = sort(str);// å符串æåº
System.err.println(str);// æå°ç»æ
statistic(str);// ç»è®¡åç±»å符æ°ç®
}
}
public class CharsSort {
// æåº,éç¨å泡æåºæ³
public static String sort(String str) {
char chs[] = str.toCharArray();
int size = chs.length;
char temp;
for (int i = 0; i < size; i++) {
for (int j = size - 1; j > i; j--) {
if (chs[j] < chs[j - 1]) {
temp = chs[j];
chs[j] = chs[j - 1];
chs[j - 1] = temp;
}
}
}
return new String(chs);
}
// ç¨åç»è®¡åç±»å符æ°ç®
public static void statistic(String str) {
int countOfNumber = 0;// æ°åçæ°ç®
int countOfLeter = 0;// åæ¯çæ°ç®
int countOfSymbol = 0;// 符å·çæ°ç®
char[] chs = str.toCharArray();
int size = chs.length;
// å¤æå符类å,åç±»ç»è®¡
for (int i = 0; i < size; i++) {
if ((chs[i] < 'z' && chs[i] > 'a')
|| (chs[i] < 'Z' && chs[i] > 'A')) {
countOfLeter++;
} else if (chs[i] < '9' && chs[i] > '0') {
countOfNumber++;
} else {
countOfSymbol++;
}
}
// æå°ç»è®¡ç»æ
System.err.println("å å«åæ¯:" + countOfLeter + "个");
System.err.println("å å«æ°å:" + countOfNumber + "个");
System.err.println("å å«å ¶ä»ç¬¦å·:" + countOfSymbol + "个");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// æµè¯ç»æ
String str = "68765Shfsa*3219(6faylahjyAbo81av)tiA52N<6#6&0_84";
str = sort(str);// å符串æåº
System.err.println(str);// æå°ç»æ
statistic(str);// ç»è®¡åç±»å符æ°ç®
}
}
温馨提示:答案为网友推荐,仅供参考