拿到s后直接转char数组,然后sort完在StringBuffer里面拼接起来,输出即可
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { String s = sc.nextLine(); int len=s.length(); char[] arr = s.toCharArray(); Arrays.sort(arr); StringBuffer sb=new StringBuffer(); for(int i=0;i<len;i++){ sb.append(arr[i]); } System.out.println(sb); } } }