import java.util.Arrays;
/**
* 冒泡排序输出数组
*/
public class Main {
public static void main(String[] args) {
int[] ns = { 28, 12, 89, 73, 65, 18, 96, 50, 8, 36 };
System.out.print("排序前数组:");
System.out.println(Arrays.toString(ns));
for (int i = 0; i < ns.length; i++) {
for (int j = 0; j < ns.length - i - 1; j++) {
if (ns[j] > ns[j + 1]) {
int temp = ns[j];
ns[j] = ns[j + 1];
ns[j + 1] = temp;
}
}
}
System.out.print("排序后数组:");
System.out.println(Arrays.toString(ns));
}
}
Java冒泡排序遍历数组
最新推荐文章于 2021-08-01 20:39:02 发布