package oop;
import java.util.Arrays;
public class SortDemo {
/**
* @param args
*/
public static void main(String[] args) {
int [] array=new int[]{3,19,5,6,8};
/*Arrays.sort(array);
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
System.out.println(array[0]);
System.out.println(array[array.length-1]);*/
//冒泡排序
for (int i = 0; i < array.length-1; i++) {
for (int j = i,t=i+1; j < array.length; j++,t++) {
if(t<array[j])
{
int temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
//下面是增强for
// for(int a:array)
// {
// System.out.println(a);
// }
}
}
|
|