public static void test2(){
Scanner sc = new Scanner(System.in);
//循环,当循环次数固定的时候
//初始化条件:int i = 1;
//循环条件:i<=5;
//输入课程成绩,并计算和,最后计算平均分 (和/5)
//循环迭代:i++;
int score = 0; //成绩的变量
int sum = 0; //和的变量
for(int i = 1;i<=5;i++){
System.out.println("请输入第"+i+"门课程的成绩:");
score = sc.nextInt(); //从控制台中输入成绩
sum = sum+score; //10 100
}
int avg = sum/5; //平均分
System.out.println("平均分是:"+avg);
}