import java.util.Random;
public class Sj{
public static void main(String [] args){
int num = 0;
//生成10个20000以内的随机数,并求和
int [] date = new int[10];
Random rand = new Random();
for ( int i=0;i<date.length;i++) {
date[i] = rand.nextInt(20000)+1;
num += date[i];
System.out.println(date[i]);
}
System.out.println("随机数总和:"+num);
//用插入排序法对10个随机数从小到大进行排列
for ( int row=0;row<date.length-1;row++) {
int curr = date[row+1];
for ( int col=row;col>=0;col--) {
if ( curr<date[col]) {
date[col+1] = date[col];
}
else{
break;
}
date[col] = curr;
}
}
for ( int i=0;i<date.length;i++) {
System.out.print(date[i]+"\t");
}
}
}
12-30
4080

09-09
1万+

07-18
6685
