java 阵列Soritn从高到低

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 阵列Soritn从高到低相关的知识,希望对你有一定的参考价值。

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BASICJAVA;

import java.util.Scanner;

/**
 *
 * @author ABIR
 */
public class Array_Sorting_High_To_High {
    public static void main(String[]args){
        Scanner abir =new Scanner(System.in);
        int[] number=new int[5];
        for (int i = 0; i < number.length; i++) {
            System.out.println("Enter your "+(i+1)+" number");
            number[i]=abir.nextInt();
        }
        for (int i = 0; i < number.length; i++) {
            //saving the number as minimum
            int max=number[i];
            int maxindex=i;
            for (int j = i+1; j < number.length; j++) {
                if(number[j]>max){
                    max=number[j];
                    maxindex=j;
                }
            }
            int backup=number[i];
            number[i]=number[maxindex];
            number[maxindex]=backup;
        }
        System.out.println("After Sorting");
        for (int i = 0; i < number.length; i++) {
            System.out.println(number[i]);
        }
    }
}

以上是关于java 阵列Soritn从高到低的主要内容,如果未能解决你的问题,请参考以下文章

java编程一个可以 进行多个选择题测验成绩(从高到低依次输出学生下标和成绩(可以重复))

Android 11.0 Camera 分辨率从高到低排列

Android 系统APK-Camera 将相机像素从高到低降序排列

joomla php从高到低排序数组[重复]

没有内置的从高到低排序[关闭]

从高到低! 英语怎么讲