源码如下:
package Another;
public class Arr {
public static void main(String[] args) {
int[] arr1 = { 22, 14, 11, 66, 2 };
Bubble ble=new Bubble();
ble.sort(arr1);
for (int i = 0; i < arr1.length; i++) {
System.out.print(arr1[i] + " ");
}
}
class Bubble {
public void sort(int[]arr) {
int temp = 0;
for (int i = 1; i < arr.length; i++) {
for (int j = 0; j < arr.length - i; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
}
}
package Another;
public class Arr {
public static void main(String[] args) {
int[] arr1 = { 22, 14, 11, 66, 2 };
Bubble ble=new Bubble();
ble.sort(arr1);
for (int i = 0; i < arr1.length; i++) {
System.out.print(arr1[i] + " ");
}
}
class Bubble {
public void sort(int[]arr) {
int temp = 0;
for (int i = 1; i < arr.length; i++) {
for (int j = 0; j < arr.length - i; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
}
}










