ASCII码排序
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input输入数据有多组,每组占一行,有三个字符组成,之间无空格。Output对于每组输入数据,输出一行,字符中间用一个空格分开。
Sample Input
qwe asd zxc
Sample Output
e q w a d s c x z
1 package Ascll码排序; 2 3 import java.util.Scanner; 4 5 public class p1 { 6 public static void main(String[] args) { 7 Scanner sc = new Scanner(System.in); 8 while(sc.hasNext()) { 9 String str = sc.next(); 10 int a = str.charAt(0); 11 int b = str.charAt(1); 12 int c = str.charAt(2); 13 int temp; 14 if(b>a) { 15 temp = a; 16 a = b; 17 b = temp; 18 19 } 20 if(c>a) { 21 temp = a; 22 a = c; 23 c = temp; 24 } 25 if(c>b) { 26 temp = b; 27 b = c; 28 c = temp; 29 } 30 System.out.println((char)c+" "+(char)b+" "+(char)a); 31 } 32 } 33 }