public class Demo {
public static void main(String[] args){
int a[] = new int[10];
int temp;
for(int i =0; i < 10; i++){
a[i] = (int)(Math.random()*100);
}
for(int i = 0; i < 10; i++){
for(int j = i+1; j < 10; j++){
if(a[i] > a[j]){
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(int i = 0; i < 10; i++){
System.out.print(a[i] + " ");
}
}
}
import java.util.Random;
public class Rand {
public static void main(String[] args) {
//声明长度为10的数组
int num[]=new int[10];
//得到0-99以内的10个随机数,并将其保存到数组中
for (int i = 0; i < num.length; i++) {
Random rand=new Random();
num[i]=rand.nextInt(100);
}
//将产生的10个随机数进行从小到大的排序
for (int i = 0; i < num.length; i++) {
for (int j = 0; j < num.length-i-1; j++) {
if(num[j]>num[j+1]){
int temp=0;
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
}
//最后将排好序的数组打印出来
System.out.println("将产生的10个随机数进行从小到大的排序:");
for (int i = 0; i < num.length; i++) {
System.out.print(num[i]+"\t");
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int al[]=new int [10];
Random r=new Random();
for(int i=0;i<10;i++){
int a=r.nextInt(100);
//System.out.println(a);
al[i]=a;
}
for(int i=0;i<10;i++){
Arrays.sort(al);
System.out.println(al[i]);
}
}