获取数组中值的百分比(Java)



对于一项任务,用户需要为主队输入8分,为对手队输入8分数。任务的Park要求输出显示主队的比赛次数,以及主队整个赛季的获胜百分比。代码如下:顺便说一句,这项任务需要更多的步骤和方法,这些步骤和方法都很完美,只有这个步骤/方法不是。

public static void main (String [] args){
    final int tGame = 8;
    final int oGame = 8;
    int [] texansScore;
    int [] opponentsScore;;
    texansScore = new int [8];
    opponentsScore = new int [8];
    Scanner sc = new Scanner(System.in);
    for (int t = 0; t < 8; t++){
        System.out.println("Score for Game " + (t + 1) + ": ");
        System.out.println(" Please enter in the Houston Texans'score: ");
        texansScore [t] = sc.nextInt();
        System.out.println(" Please enter in the opponents' score: ");
        opponentsScore [t] = sc.nextInt();

        }
        dterminePercent(texansScore, opponentsScore);
}
public static double dterminePercent ( int [] tGame, int [] oppGame){
        int [] array = new int [tGame.length];
        double won = 0;
        double winPercent = 0;
        for (int i =0; i < tGame.length; i++){
            if ( tGame [i] > oppGame [i]){
            array [i] = tGame[i];
            won = i + 1;
        }
            winPercent = won / 8.0 * 100.0;
        }
        System.out.println("The amount of games won is: " + won + "nThe win perecntage is: " + winPercent + "%");
        return winPercent;
    }

won = i + 1;更改为won ++;。您希望递增won,而不是使其比循环索引i高一。

最新更新