java基础-- for循环-依次录入学生成绩

mac2022-06-30  52

在Java用for循环依次录入学生成绩:

1 package Cforth; 2 3 import java.util.Scanner; 4 5 public class C4_15 { 6 public static void main(String[] args) { 7 Scanner in = new Scanner(System.in); 8 int sum = 0; 9 10 for (int j = 0; j < 5; j++) { 11 System.out.println("请输入你的" + (j + 1) + "个成绩"); 12 int score = in.nextInt(); 13 sum = sum + score; 14 } 15 int a = sum / 5; 16 System.out.println("平均分:" + a); 17 } 18 }

测试结果:

测试成功!

转载于:https://www.cnblogs.com/Catherinezhilin/p/8398121.html

相关资源:java学生成绩录入实例
最新回复(0)