首页/ 题库 / [未知题]

从高到低将从命令行读取的一组数字进行降序排序。


未知题
2021-07-17 17:55
查看答案

正确答案


从高到低将从命令行读取的一组数字进行降序排序。


import java.util.Arrays;


public class ExamDemo {


       public static void main(String[] args) {


              int[] a = new int[args.length];


              int j, temp, i;      


              for (i = 0; i < args.length; i++)  a[i] = Integer.parseInt(args[i]);


              for (i = 0; i < a.length - 1; i++){


                     for (j = 0; j < a.length - i - 1; j++){


                            if (a[j] < a[j + 1]) {


                                   temp = a [j];


                                   a[j] = a[j + 1];


                                   a[j + 1] = temp;


                            }


                     }


              }


              for (i = 0; i < a.length; i++)


                     System.out.print(a[i] + " ");


              System.out.println();


       }


}



试题解析

标签: