题解 | HJ34#图片整理#
图片整理
https://www.nowcoder.com/practice/2de4127fda5e46858aa85d254af43941
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str = scanner.nextLine(); char[] chars = str.toCharArray(); char ch = ' '; //遍历数组按ASCII从小到大排序 for (int i = 0; i < chars.length; i++) { for (int j = i + 1; j < chars.length ; j++) { //若前大于后则交换位置 if (chars[i] > chars[j]) { ch = chars[i]; chars[i] = chars[j]; chars[j] = ch; } } } //排列后即可输出 // System.out.print(Arrays.toString(chars)); for (char c : chars) { System.out.print(c); } } }