第1个回答 2010-01-06
public class Ex{
public static void main(String args[])
{
int a[]={2,5,4,3,1}; //定义数组
int temp=0; //临时变量,用于储存排序时的数据
for(int i=0;i<5;i++)
{
for(int j=i;j<5;j++)
{ // 冒泡排序
if (a[j]>a[i])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(int i=0;i<5;i++)
{
System.out.println(a[i]);
}
}
}
第2个回答 2010-01-06
int[] arr = {1,5,6,7,8};
Arrays.sort(arr);
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}