给定一组无序的整数,按升序排序输出这些整数

A.给定一组无序的整数,按升序排序输出这些整数
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 307 (52 users) Total Accepted: 56 (48 users) Special Judge: No
Description
一组无序的整数,按升序排序输出这些整数。
Input
待排序的若干个整数
Output
按升序排序的数
Sample Input
90,-12,1,56,65,7,89,3
Sample Output
-12,1,3,7,56,65,89,90
Hint
排序算法不限定






import java.util.*;
import java.math.*;
public class Main {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str = input.next();
  String[] strarr=str.split(",");
  int a[];
  a = new int[strarr.length];
  for(int i=0;i<strarr.length;i++){
  a[i]=Integer.parseInt(strarr[i]);
  }
  Arrays.sort(a);
  for(int i=0; i<strarr.length; i++)
  {
  if(i == strarr.length-1)
  {
  System.out.printf("%d",a[i]);
  }
  else
  {
  System.out.printf("%d,",a[i]);
  }
  }
}
}


猜你喜欢

转载自blog.csdn.net/wonder__/article/details/79934895