猿问

数组怎么从大到小?

public static void main(String[] args) {

int score[]={1,5,6,7,8,3,4,2,9};

Arrays.sort(score);

for(int i=0;i<score.length;i++){

System.out.println(score[i]);

}

运行结果

1

2

3

4

5

6

7

8

9

怎么从大到小排列?

慕村6263914
浏览 1900回答 5
5回答

望远

package com.gnnu2016; import java.util.Arrays; import java.util.Scanner; public class HelloWorld {   public static void main(String[] args) {   int score[]={1,5,6,7,8,3,4,2,9};//定义整形数组score,有9个元素下标0-8   Arrays.sort(score);//调用sort()方法,实现数组的升序排序   for(int i=score.length-1;i>=0;i--){//for循环逆序打印输出   System.out.print(" "+score[i]);//scores.length是当前scores数组的元素个数,之所以-1是因为下标从0开始   } } }

按照自己的节奏前行

简单的说sort方法还有一个倒序的参数,你添加上就支持倒序了

望远

for(i=score.length-1;i>=0;i--)

好好先生28

从后往前遍历不就行了

慕婉清5044891

BPYODFBDGCRTJYBWZUDMVLWZOQGCEVXSOLUDTCRGPKUWMHRHXEHWFHQLACLAKACSOQNCFUKZAWSBQRZBETWSUDUXLGIRVRNOQMIBKMJSUKACXTXGPYTPEMVFIBXYNDSCETDMOWYOQLNDFIXJLTQYOXTNWNOQFBDGJEAJGPEGXZPLHQMTSBQFHXGAWZOGCJGDFIEZJLHJYHKMCMIYGLACYNDMCRMBBRZPRTOXGPLXZIWLAQZVEGAPRBSHQMBYUQFVKTPLUJSIEMUDTILAJFTGBXGISOWEIEVKZOXNNWZVKTTCFVEZIRHKFMOENWSIKNCOQSIRTWGADMKZCLODFIRNJLUWDUJSVKGVFOPMMVENWFHYTPYAWZBXGOESOQZCFIENQZBVLNPEAJMCOCLHIXAJYBQWFUJSIPSOEOBRTCXAVLGJFFNDNVLMJRBDUJSUKRNJFCYIQZPSAIXAWZFUJMOXTVKIXKSUKZETQZDMUPPLODTVYUXDFZOLUWZCLOPYTQSUQGUKZBJMTPFBQAJZZOXTQFIKTCSTVENHQFHKAIEZBKAWMCSBCABQGPYGWSJSCLNUJZBDGQZHDFIQMCENPFQKZILHJYBDTBRTJSHDFIROSTWFOKNCSUQJENJAPEHQFOMUJFBXTVKVDOXMWDZUXZCSAWBFVERGQKNUVYAQEFIEUDRRNPLHDZVLOOQRNKZIFVCYRTILNCLNJMOQFBEHCEACSBUWSUKTPELWLFBDZVEVXTJXAPLNQZPLNXMAIXNPSOWZILOQTPYNQMORNSOXACEGPFUQXFOKAPEAQZIXSHEGJSNJMIUWRIRNNWZPRXGVRTPRTJNCLTVRHPRHQFJQLADSBKZVDTNCSIEZCYAIKIKMVLGPEAXE

路路路飞

冒泡排序法
随时随地看视频慕课网APP

相关分类

Java
我要回答