Java array -- Bubble sorting, java array bubbling
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 ("before Bubble Sorting:"); 12 System. out. println ("Number" + (0) + "Times:" + Arrays. toString (arr); 13 14 bubbleSort (arr); 15 System. out. println ("before Bubble Sorting:"); 16 System. out. println ("Number" + (0) + "Times:" + Arrays. toString (arr); 17} 18/* 19 * bubble sort 20 */21 public static void bubbleSort (int a []) {22 for (int I = 0; I <. length-1; I ++) {23 for (int j = 0; j <. 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 ("no." + (I + 1) + "Times:" + Arrays. toString (a); 31} 32} 33}