package HomeWork;
public class Test27 {
/*
* 、为教师编写一个程序,该程序使用一个数组存储 30 个学生的考试成绩,
* 并给各个数组元素指定一个1-100 的随机值,然后计算平均成绩
*/
public static void main(String[] args) throws Exception{
int sco[] = new int[31];//创建学生成绩数组
double avg = 0;//定义平均分
double sum = 0;//定义总分
for(int i= 1;i<=30;i++){
sco[i] = (int) (Math.random()*100);
}
for(int i = 1;i<=30;i++){
sum=sum+sco[i];
avg = sum/30;
}System.out.println("学成的成绩是:");
for(int i = 1;i<=30;i++){
if(i%5==0){
System.out.println();
}
System.out.print(sco[i]+"\t");
}
System.out.println("\n平均成绩是:"+avg);
}
}