package sort;
/**
* 冒泡排序
* @author Brook Lieu
* @version v1.0 2014-9-28
*/
public class MaoPao {
public static void main(String[] args) {
int[] strings = new int[] {9,6,7,5,8,3,4,2,1,34,-43};
int temp;
for (int i=strings.length-1; i>0; i--) {
for (int j=0; j<i; j++) {
if (strings[j]>strings[j+1]) {
temp = strings[j];
strings[j] = strings[j+1];
strings[j+1] = temp;
}
}
}
for (int i=0; i<strings.length; i++) {
System.out.print(strings[i] + " ");
}
}
}
执行该代码后输出:
-43 1 2 3 4 5 6 7 8 9 34