怎样用JAVA语言对数组a[10](顺序是乱的)进行由小到大的排序

最好详细点 要能运行出来的
谢谢各位了啊!

冒泡排序

int [] a= new int[]{45,32,4,11,9,6,17,9,10,89};

for(int i =1;i<a.length;i++){
for(int j=0;j<a.length-i;j++){
if(a[j]>a[j+1]){
int temp = a[j];
a[j]= a[j+1];
a[j+1]= temp;
}
}
}

for(int i=0;i<a.length;i++){
System.out.println(a[i]);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-07-14
直接调用Arrays.sort();方法就是了哈。。

默认就是升序排列的哈。。
import java.util.Arrays;

public class TwoNums {

public static void main(String[] args) {
int[] nums1 = new int[]{1, 3, 2, 4, 5, 6, 7 ,8, 9};
Arrays.sort(nums1);
for(int num : nums1) {
System.out.println(num);
}

}
}
第2个回答  2010-07-14
import java.util.Arrays;
int []a={1,3,2,4,5,6,8,7,9,10};
Arrays.sort(a);
第3个回答  2010-07-14
建议你看下集合章节里的排序,方法一楼已经说了,用arrays.sort()最简单
相似回答
大家正在搜