package com.huan; import java.util.Arrays; import java.util.Random; public class BubbleSort { public static void main(String[] args) { int[] data = new int[10]; for (int i = 0; i < 10; i++){ data[i] = new Random().nextInt(1000); } System.out.println(Arrays.toString(data)); for (int i = 1; i < 10; i++){ for (int j = 0; j < 10-i; j++){ if(data[j] > data[j+1]){ int temp = data[j]; data[j] = data[j+1]; data[j+1] = temp; } } } System.out.println(Arrays.toString(data)); } }