用Math.random()方法随机生成十个学生的成绩,计算这十个学生的平均成绩

来源:互联网 发布:eve有mac版吗 编辑:程序博客网 时间:2024/05/21 09:13
package tag;/* * 用Math.random()方法随机生成十个学生的成绩,计算这十个学生的平均成绩 *  */public class Test3 {public static void main(String[] args) {int sum = 0;for (int i = 0; i < 10; i++) {int stu = (int) (Math.random() * 100);sum += stu;System.out.println("第" + (i + 1) + "个学生的成绩:" + stu);}System.out.println("这十个学生的平均成绩为:" + sum / 10);}}

阅读全文
0 0
原创粉丝点击