目錄
一:冒泡排序思想
二:冒泡排序代碼
三:結(jié)果
一:冒泡排序思想
二:冒泡排序代碼
package totoSort;
import java.util.Arrays;
public class TotoSort {
public static void main(String[] args) {
int[] arrays = new int[] {6,5,4,3,2,1};
System.out.println(Arrays.toString(arrays));
sort(arrays);
System.out.println(Arrays.toString(arrays));
}
public static void sort(int[] arrays) {
int temp = 0;
//比較幾輪
for(int i = 0; i < arrays.length - 1; i++) {
for(int j = 0; j < arrays.length - 1 - i; j++) {
if(arrays[j] > arrays[j + 1]) {
temp = arrays[j];
arrays[j] = arrays[j + 1];
arrays[j + 1] = temp;
}
}
}
}
}
三:結(jié)果
文章來源:http://www.zghlxwxcb.cn/news/detail-624166.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-624166.html
到了這里,關(guān)于java冒泡排序(含冒泡排序代碼)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!