{ 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); }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案