Java在每个索引总数之后得到平均值

时间:2015-01-29 20:06:52

标签: java arrays for-loop recursion

我试图弄清楚如何实现我的SCORES和VOTES,我没有遇到任何问题。我感到困惑,似乎无法解决的问题是我将如何回顾我的参赛者阵容并获得他们在总分数或投票中的百分比。例如,球员1的得分为10,总得分为30,球员2的得分为15/30等等...跑动平均值不是问题,这是一个真正的总平均值我似乎无法包裹我的头。任何建议都会很棒。

 package contestscore;
 import java.util.*;

 public class ContestScore {



   public static void main(String[] args) {
    // TODO code application logic here

    Scanner keyboard = new Scanner(System.in);
    System.out.println("Enter number of contesants: ");
    int numContest = keyboard.nextInt();
    System.out.println("Enter contestants DANCE SCORE and NUMBER OF VOTES    EARNED: ");
    int[] danceScore = new int[numContest+1];
    int[] numVotes = new int[numContest+1];
    double avgDanceScore = 0.0;
    double avgVoteScore = 0.0;
    double totalDanceScore = 0.0;
    int numContestIndex = 0;
    double avgContestDanceScore = 0.0;
    int totalVotes = 0;
    double avgContestVote = 0.0;

    for(numContestIndex = 1; numContestIndex <= numContest; numContestIndex++)
    {
        danceScore[numContestIndex] = keyboard.nextInt();
        numVotes[numContestIndex] = keyboard.nextInt();
        System.out.println("DANCE SCORE: "+danceScore[numContestIndex]);
        System.out.println("NUMBER OF VOTES: "+numVotes[numContestIndex]);


        totalDanceScore = totalDanceScore + danceScore[numContestIndex];
        //avgContestDanceScore = danceScore[numContestIndex]                                                                               /totalDanceScore;
        System.out.println("TOTAL DANCE SCORE: "+totalDanceScore); 

        totalVotes = totalVotes + numVotes[numContestIndex];
        //avgContestVote = numVotes[numContestIndex] / totalVotes;
        System.out.println("TOTAL CONTESTANT VOTE SHARE: "+totalVotes);

0 个答案:

没有答案