java中Arrays.sort是降序,那升序是什么?

方法我就不写了下面给你个冒泡排序吧 //从小到大for (int i = 0; i < num.length-1; i++) { for (int j = 0; j < num.length-1-i; j++) { if(num[j] > num[j+1]){ int temp = num[j]; num[j] = num[j+1]; num[j+1] = temp; } } ...
java中Arrays.sort是降序,那升序是什么?
方法我就不写了下面给你个冒泡排序吧
//从小到大for (int i = 0; i < num.length-1; i++) { for (int j = 0; j < num.length-1-i; j++) { if(num[j] > num[j+1]){ int temp = num[j]; num[j] = num[j+1]; num[j+1] = temp; } } }//从大到小for (int i = 0; i < num.length-1; i++) { for (int j = 0; j < num.length-1-i; j++) { if(num[j] < num[j+1]){ int temp = num[j]; num[j] = num[j+1]; num[j+1] = temp; } } } 其实 我就改变了它的判断条件
2013-10-08
那就使用Arrays.sort(T[] a,
Comparator<? super T> c),自己写个Comparator即可2013-10-08
没有升序 你只能降序以后 把数组反过来输出2013-10-08
升序是你把返回的数组倒序输出。2013-10-08
升序要实现comp..able 接口2013-10-08
升序要重写compareTo方法,具体明天给你,今天太晚了2013-10-08
mengvlog 阅读 10 次 更新于 2025-07-20 08:30:35 我来答关注问题0
  •  周建国伟 用java语言编程:从键盘输入30个整数,然后进行排序(按从小到大)。 急!!

    import java.util.Scanner;public class Test { public static void main(String[] args) { int num[] = new int[30];Scanner scanner = new Scanner(System.in);for (int i = 0; i < num.length; i++) { num[i]= scanner.nextInt(); //读取30个数存进num } Arrays.sort(num);...

  •  过客守望者 c语言中的merge函数

    merge()是C++标准库的函数,主要实现函数的排序和合并,不仅仅是合并,具体要求参照标准库。include"stdafx.h"include include include include usingnamespacestd;boolcomp(constinti,constintj){ returni>j;} intmain(void){ /*自定义谓词*/ std::arraya...

檬味博客在线解答立即免费咨询

Java相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部