急求: 编写一个JAVA程序,对10个数进行从小到大的排序

如题所述

第1个回答  2011-01-02
public class Sort {

/**
* Creates a new instance of <code>Sort</code>.
*/
public Sort() {

}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//先定义一个数组,存放10个数
int[] a={10,50,2,55,65,12,58,92,4,59};
int temp;
for(int j=0;j<a.length;j++)
{
for(int i=0;i<a.length-1;i++)
{
if(a[j]<a[i])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.print("从小到大的排序为:");
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+",");
}
}
}本回答被网友采纳
第2个回答  2011-01-03
用冒泡排序,或者快速排序,查资料吧!一些经典的排序算法还是要学的....