java冒泡排序典型例子,请收藏,然后背会,默写会!
public class BubblesSort {
public static void main(String[] args) {
int array[] = { -1, 10, 3, 27, 15, 8 };
for (int i = 0; i < array.length – 1; i++) {
for (int j = 0; j < array.length – i – 1; j++) {
if (array[j] > array[j + 1]) {
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
}
}
转载请注明来源网站:blog.ytso.com谢谢!
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/14933.html