用数组来实现简单的冒泡排序
package Array;
public class BubbleSort{
public static void main(String[] args){
int[] scores = {20,90,10,25,30,56};
sort(scores);
for(int i = 0; i < scores.length; i++) {
System.out.println(scores[i]);
}
}
/**
* 这个里面写的是冒泡排序的算法
*/
public static void sort(int arrays[]){
//第一次循环是来总共的遍历次数 最后一个不需要遍历
//因为换下来最后一个必定是最大的
for(int i = 0; i < arrays.length-1; i++) {
/**
* 第二次循环是拿来比较的那些元素
* 首先最开始的时候一个都没有遍历,拿首元素来比较,然后需要比较的是长度-遍历过了的元素-本身
*/
for(int j = 0; j < arrays.length - i - 1; j++) {
int temp;
if(arrays[j] > arrays[j + 1]){
temp = arrays[j];
arrays[j] = arrays[j + 1];
arrays[j + 1] = temp;
}
}
}
}
}