import java.util.Arrays
import java.util.Scanner
public class JTest {
public static void main(String[] args) {
String []str=new String[3]
char[] ch=new char[3]
for (int i = 0i <3i++) {
str [i]= new Scanner(System.in).next()
for(int j=0j<str.lengthj++){
ch=str[i].toCharArray()
Arrays.sort(ch)
}
for(int l=0l<3l++){
System.out.print(ch[l]+" ")
}
System.out.println()
}
}
}
char的值即为其ascii码值..因此.代码如下public class CharsSort {
// 排序,采用冒泡排序法
public static String sort(String str) {
char chs[] = str.toCharArray()
int size = chs.length
char temp
for (int i = 0i <sizei++) {
for (int j = size - 1j >ij--) {
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 = 0i <sizei++) {
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)// 统计各类字符数目
}
}