题解 | #图片整理#
图片整理
https://www.nowcoder.com/practice/2de4127fda5e46858aa85d254af43941
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String str = bf.readLine(); char[] ch = str.toCharArray(); int[] arr = new int[ch.length]; for (int i = 0; i < ch.length; i++) { int ascCode = (int) ch[i]; arr[i] = ascCode; } Arrays.sort(arr); // 转码 for (int i = 0; i < arr.length; i++) { char val = (char) arr[i]; System.out.print(val); } } }
1.先遍历,转成ASCII码。放入集合中进行排序
2.再转成char,输出
#华为OD机考#