中华考试网·阅读新闻
编程开发 > JAVA > 文章内容

JAVA编程入门教程(25)

2015-11-26编辑:guomu

求学员平均成绩

import java.util.*;

public class Test{

       public static void main(String[] args){

              Scanner in=new Scanner(System.in);

              System.out.println("请输入学生的人数:");

              int person=in.nextInt();

              int i=1;

              int sum=0;

              while(i<=person){

                     System.out.println("请输入第"+i+"个学员的成绩:");

                     int a=in.nextInt();

                     sum=sum+a;

                     i++;

              }

              int age=sum/person;

              System.out.println(person+"个人平均成绩为"+age);

       }

}

JAVA编程入门教程(24)
咨询热线:4000-525-585(免长途费)