如题
给出完整代码啊,大哥大姐们
package cn.itcast;
public class pubbleSort {
public static void main(String[] args) {
int[] arr = { 84, 65, 95, 8, 63, 54, 25, 68, 47, 77, 58, 54, 69, 55, 58, 4, 5, 55, 48, 87, 45, 58, 54, 12, 25,
49 };
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
if (i == arr.length - 1) {
System.out.println("");
}
}
System.out.println("--------------------------" );
// å泡æåºæ¹æ³
for (int i = 0; i < arr.length - 1; i++) {
for (int x = 0; x < arr.length - 1-i; x++) {
if (arr[x] > arr[x + 1]) {
// æ°å¼äº¤æ¢
int a = arr[x];
arr[x] = arr[x + 1];
arr[x + 1] = a;
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
if (i == arr.length - 1) {
System.out.println("");
}
}
}
}
public class pubbleSort {
public static void main(String[] args) {
int[] arr = { 84, 65, 95, 8, 63, 54, 25, 68, 47, 77, 58, 54, 69, 55, 58, 4, 5, 55, 48, 87, 45, 58, 54, 12, 25,
49 };
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
if (i == arr.length - 1) {
System.out.println("");
}
}
System.out.println("--------------------------" );
// å泡æåºæ¹æ³
for (int i = 0; i < arr.length - 1; i++) {
for (int x = 0; x < arr.length - 1-i; x++) {
if (arr[x] > arr[x + 1]) {
// æ°å¼äº¤æ¢
int a = arr[x];
arr[x] = arr[x + 1];
arr[x + 1] = a;
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
if (i == arr.length - 1) {
System.out.println("");
}
}
}
}
温馨提示:答案为网友推荐,仅供参考