Java Arrays.sort():数组排序

Arrays.sort():数组排序
 1 /*
 2  * 1.键盘录入三个整数,按照从小到大的顺序输出 
 3  * 2.如果用户输入的是3 2 1,程序运行后打印格式"按照从小到大排序后的顺序为:1 2 3  
 4  */
 5 public class Demo2 {
 6     public static void main(String[] args) {
 7         int[] array = new int[3];
 8         Scanner sc = new Scanner(System.in);
 9         System.out.println("输入3个数据:");
10         for (int i = 0; i < array.length; i++) {
11             System.out.println("输入第"+(i+1)+"个数据");
12             array[i] = sc.nextInt();
13         }
14         Arrays.sort(array);
15         for(int j=0;j<array.length;j++) {
16             System.out.print(array[j]+" ");
17         }
18     }
19 }
原文地址:https://www.cnblogs.com/chenyuan7/p/9529293.html