如何从数组中读取两个值并确定哪个值更大?

时间:2016-03-14 01:32:51

标签: java arrays

我是编程的新手,我遇到了一个我遇到的挑战。

我们有一个数组(Integer [] []匹配),有几个数组,每个匹配得分(Integer [] match_result)。如果match_result [0]大于match_result [1],则将其计为胜利。如果匹配[0]小于匹配[1],则将其计为丢失。如果他们相等,那就是平局。我需要确定比赛总数中的胜负百分比。这是我最初给出的:

public class Main {

public static void main(String args[]){

    Integer[][] matches = {{2,2},{3,2},{4,1},{1,3},{3,5},{1,1},{1,0},{0,0},{1,2},{0,2},{0,3},{3,3},{1,0}};
    System.out.println(results(matches));

}

public static String results(Integer[][] matches){
    Integer percentWin = 0;
    Integer percentLoss = 0;
    Integer percentTie = 0;
    Integer amountOfMatches = 13;


Integer win=0; //added by me
Integer lost=0; //added by me
Integer tie=0; //added by me

    for (int i = 0; i<amountOfMatches; i++){
        Integer nrMatch = i;
        Integer[] match_result;


        //added by from here down

        match_result = matches[i];//edited thanks to user:immibis


            if (match_result[0]>match_result[1]) 
            win++;
            else if (match_result[0]<match_result[1])
            lost++;
            else
            tie++;


        percentWin= (win/amountOfMatches)*100;
        percentLoss= (lost/amountOfMatches)*100;
        percentTie= (tie/amountOfMatches)*100;

    }


//it's not returning the percentages, any idea why???
    return "Wins: " + percentWin + " Losses: " + percentLoss + " Ties: " + percentTie;
}

}

这就是我写的。我留下了一些我遇到问题的评论:

w2

}

0 个答案:

没有答案