JAVA字符排序--冒泡排序法

package hello;

public class SortLetter {
	public static void main(String[] args) {
		String s = "ueurybbc";
		String ns = Sort01(s);
		System.out.println(ns);
	}
	
	public static String Sort01(String s){
		char[] ch = s.toCharArray();
		char cur;
		StringBuffer sb = new StringBuffer();
		for(int j = 0; j<ch.length-1;j++){
			for(int i = 0;i<ch.length-1-j;i++){
				if(ch[i+1] < ch[i]){
					cur = ch[i];
					ch[i] = ch[i+1];
					ch[i+1] = cur;
				}
			}
		}

		return new String(ch);
	}
}

你可能感兴趣的:(JAVA,JAVA算法)