首页 > 其他 > 详细

案例:利用累加器计算前N个学生的总成绩和平均成绩

时间:2016-11-13 16:08:50      阅读:159      评论:0      收藏:0      [点我收藏+]
 1 /*
 2  *录入N个学生的成绩,并求出这些学生的总成绩和平均成绩! 
 3  * */
 4 import java.util.Scanner; 
 5 
 6 public class SumTest{
 7     public static void main(String args[]){
 8         
 9         int i = 0;
10         int sum = 0;
11         System.out.println("请输入总学生的数量:");
12         Scanner sc = new Scanner(System.in );
13         int n = sc.nextInt();
14         while( i < n){
15             i++;
16             System.out.println("请输入第"+ i + "个学生的成绩:");
17             int score = sc.nextInt();
18             sum += score;
19         }
20         System.out.println("前"+ n + "个学生的总成绩为:" + sum + "\n平均成绩为:" + (sum/n));
21     }
22 }

案例:利用累加器计算前N个学生的总成绩和平均成绩

原文:http://www.cnblogs.com/YangGC/p/6058558.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!