1个回答
2014-05-18
展开全部
import java.util.Random;
public class Test{
static void sort (int a[]){
int temp,n = a.length;
for (int i=0;i<n;i++)
for(int j=0;j<n-i-1;j++)
if(a[j] > a[j+1]) {
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
public static void main(String args[]) {
Random rand = new Random();
int array1[] = new int[10];
for (int i=0; i<array1.length; i++) {
array1[i] = (int)(Math.random()*100);
System.out.print(array1[i]+" ");
}
System.out.println("");
sort(array1);
for (int i=0 ;i<array1.length;i++)
System.out.print(array1[i] + " ");
}
}
自己写个文件编译看看
public class Test{
static void sort (int a[]){
int temp,n = a.length;
for (int i=0;i<n;i++)
for(int j=0;j<n-i-1;j++)
if(a[j] > a[j+1]) {
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
public static void main(String args[]) {
Random rand = new Random();
int array1[] = new int[10];
for (int i=0; i<array1.length; i++) {
array1[i] = (int)(Math.random()*100);
System.out.print(array1[i]+" ");
}
System.out.println("");
sort(array1);
for (int i=0 ;i<array1.length;i++)
System.out.print(array1[i] + " ");
}
}
自己写个文件编译看看
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询