• java数组--冒泡排序


     1 package demo;
     2 
     3 import java.util.Arrays;
     4 
     5 public class Demo02 {
     6     public static void main(String[] args) {
     7         int[] arr = new int[10];
     8         for(int i=0; i<arr.length; i++){
     9             arr[i] = (int) (Math.random()*100);
    10         }
    11         System.out.println("冒泡排序前:");
    12         System.out.println("第"+(0)+"次:"+Arrays.toString(arr));
    13         
    14         bubbleSort(arr);
    15         System.out.println("冒泡排序前:");
    16         System.out.println("第"+(0)+"次:"+Arrays.toString(arr));
    17     }
    18     /*
    19      * 冒泡排序
    20      */
    21     public static void bubbleSort(int a[]) {   
    22        for (int i = 0; i < a.length - 1; i++) {   
    23                for (int j = 0; j < a.length - 1; j++) {   
    24                    if (a[j] > a[j + 1]) {   
    25                        int temp = a[j];   
    26                        a[j] = a[j + 1];   
    27                        a[j + 1] = temp;   
    28                    }   
    29             }
    30                System.out.println("第"+(i+1)+"次:"+Arrays.toString(a));
    31        }
    32     }   
    33 }
    愿我们漂泊半生, 归来仍少年!
  • 相关阅读:
    Queries about less or equal elements CodeForces
    Session in BSU CodeForces
    基环树
    骑士 HYSBZ
    Valid BFS? CodeForces
    Trips CodeForces
    The writing on the wall 南京网络赛2018B题
    Building a Space Station
    Constructing Roads
    Networking
  • 原文地址:https://www.cnblogs.com/Lonnn/p/6522986.html
Copyright © 2020-2023  润新知