package com.karl1; import java.util.Scanner; public class ArrayTest1 { public static void main(String[] args) { //评委打分 //定义动态初始化数组,储存6个评委的打分 double[] scores=new double[6]; Scanner sc=new Scanner(System.in); //遍历数组每个位置,录入评委分数,录入到数组中去 for (int i = 0; i < scores.length; i++) { System.out.println("请您输入当前选手分数"+(i+1)+"个评委的分数:"); double score=sc.nextDouble(); scores[i]=score; } //遍历数组中的每个元素进行求和 double sum=0; for (int i = 0; i < scores.length; i++) { sum+=scores[i]; } System.out.println("最终选手的平均分是:"+sum / scores.length); } }
标签:double,sum,System,案例,scores,评委,打分 From: https://www.cnblogs.com/Karl-hut/p/17437946.html