0
点赞
收藏
分享

微信扫一扫

HDOJ4_ASCII码排序


Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。

Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。

Output
对于每组输入数据,输出一行,字符中间用一个空格分开。

Sample Input

qwe
asd
zxc

Sample Output

e q w
a d s
c x z

import java.util.Arrays;
import java.util.Scanner;

class Main{
private static Scanner scanner;

public static void main(String[] args) {
scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String a = scanner.next();
char[] ch = a.toCharArray();
Arrays.sort(ch);
System.out.println(ch[0]+" "+ch[1]+" "+ch[2]);
}
}
}

这个题目不难
首先接收一个字符串,用toCharArray()方法将其转换为字符串数组
再用sort()方法排序一下,sort()的排序是升序的
最后将这三个字符串打印就OK


举报

相关推荐

0 条评论