冒泡排序

xiaoxiao2021-02-28  87

public class MaoPao {

    public static void main(String[] args) {

//调用方法的做法

        int [] arr ={20,15,2,3,6,9,0};         Arrays.sort(arr);         System.out.println(Arrays.toString(arr));

    }

//使用算法的做法

   int[] arr = { 14, 34, 3, 2, 65, 890, 980 };    for (int i = 0; i < arr.length - 1; i++) {         for (int j = 0; j < arr.length - 1 - i; j++) {             if (arr[j] > arr[j + 1]) {                int temp = arr[j];                 arr[j] = arr[j + 1];               arr[j + 1] = temp;             } }    
转载请注明原文地址: https://www.6miu.com/read-67225.html

最新回复(0)