黑马程序员技术交流社区
标题:
对字符串中字符进行自然排序:
[打印本页]
作者:
Over_Mstuang
时间:
2015-8-14 01:28
标题:
对字符串中字符进行自然排序:
package overLianXi;
import org.omg.CORBA.PUBLIC_MEMBER;
public class LianXi {
public static void main(String[] args) {
String s = "dfjkafhsi";
char[] chs = s.toCharArray();
bubbleSort(chs);
String result = new String(chs);
System.out.println(result);
}
public static void bubbleSort(char[] chs){
for (int i = 0; i < chs.length-1; i++) {
for (int j = 0; j < chs.length-1-i; j++) {
if (chs[j]>chs[j+1]) {char ch = chs[j];
chs[j] =chs[j+1];
chs[j+1] = ch;
}
}
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2