public static void main(String[] args) throws ClassNotFoundException
{
int[] a = {5,7,9,6,3,1}; change(a); for(int i : a ){ System.out.print(i+"_");
}
}
//从大到小
public static void change(int[] a)
{
for(int x = 0 ; x < a.length-1 ; x++){
for(int i = 0; i < a.length-1-x; i++){
if(a[i]<a[i+1])
{
int temp = a[i]; a[i] = a[i+1]; a[i+1] =temp;
}
}
}
}
//从小到大
public static void change1(int[] a)
{
for(int x = 0 ; x < a.length-1 ; x++)
{
for(int i = 0; i < a.length-1-x; i++)
{
if(a[i] > a[i+1])
{
int temp = a[i+1];
a[i+1] = a[i];
a[i] =temp;
}
}
}
}
原文:http://www.cnblogs.com/bluecomet/p/5294931.html