杭电ACM2000ASCII码排序

ASCII码排序

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 45192    Accepted Submission(s): 18654

Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
 
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
 
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
 
Sample Input
qwe
asd
zxc
 
Sample Output
e q w
a d s
c x z
 
 1 import java.util.Scanner;
 2 public class Main{
 3     public static void main(String[] args) {
 4         Scanner scan = new Scanner(System.in);
 5         String str;
 6         char[] ch = new char[3];
 7         char temp;
 8         while(scan.hasNext()){
 9             str = scan.next();
10             for(int i=0;i<3;i++)
11                 ch[i] = str.charAt(i);
12             for(int j=0;j<3;j++){
13                 for(int i=0;i<2;i++)
14                     if(ch[i]>ch[i+1]){
15                         temp = ch[i];
16                         ch[i] = ch[i+1];
17                         ch[i+1] = temp;
18                     }
19             }
20             for(int i=0;i<2;i++)
21                 System.out.print(ch[i]+" ");
22             System.out.println(ch[2]);
23                 
24         }
25     }
26 }
原文地址:https://www.cnblogs.com/bchxsx322/p/2459134.html