package ss1; /** * 字符串中的字符排序 */ public class Menu { public static void main(String[] args) { String s = "afbcedg"; char[] chs = arrPaiXu(s.toCharArray()); System.out.println(String.valueOf(chs)); } public static char[] arrPaiXu(char[] arr){ for (int i = 0; i < arr.length-1; i++) { for (int j = i+1; j < arr.length; j++) { if (arr[j]<arr[i]) { char temp = arr[j]; arr[j] =arr[i]; arr[i] = temp; } } } return arr; } } 結果:
abcdefg
|
|