赞
踩
编写Java程序,实现从控制台输入对应个数的整数,输出对输入整数的从大到小显示
- import java.util.Arrays;
- import java.util.Scanner;
-
- public class NumberSorting{
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入个数:");
- int i = sc.nextInt();
- int[] num = new int[i];
-
- for (int j = 0; j < i; j++) {
- System.out.println("请输入第"+(j+1)+"个整数:");
- num[j] = sc.nextInt();
- }
- Arrays.sort(num);
- System.out.println("输入完毕,排序结果如下:");
-
- for (int j = 0; j < num.length; j++) {
- System.out.println(num[j]);
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。