有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

对于作业,用户要为主队输入8分,为对手队输入8分。分配的公园要求输出显示主队一队的比赛次数以及主队整个赛季的获胜百分比。 守则如下: 顺便说一句,作业需要更多的步骤和方法,这些步骤和方法工作得很好,只有这个步骤/方法不是

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

共 (1) 个答案

  1. # 1 楼答案

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