gpt4 book ai didi

java - 我将如何为此程序创建最高分计数器以及将其放置在哪里?

转载 作者:行者123 更新时间:2023-12-01 11:39:52 27 4
gpt4 key购买 nike

我几乎完成了这项作业,我只是不明白如何创建一个“最高分计数器”来确定最高得分的游戏。这是我到目前为止的程序

import java.util.Scanner;

public class Texans {
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();
}
for (int u = 0; u < 8; u++){
System.out.println("Score for Game " + (u + 1) + ": ");
System.out.println(" Please enter in the opponents score: ");
opponentsScore [u] = 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++;
}
winPercent = won / 8.0 * 100.0;
}
System.out.println("The amount of games won is: " + won + "\nThe win perecntage is: " + winPercent + "%");
return winPercent;
}
}

我还收到“此行有多个标记” - texansScore 无法解析为 类型 - 缺少方法的返回类型 - 标记“,”存在语法错误,删除此标记 token ”错误

    dterminePercent(texansScore, opponentsScore);
}

这是我的作业详细信息

*程序应打印:

a) 休斯顿德州人队获胜的比赛百分比,

b) 休斯敦德州人队最高得分及相应的比赛号码,

c) 所有比赛的最高总得分(德州人和对手的总得分)以及相应的比赛编号。*

最佳答案

要找到最高分,您始终可以使用分数数组的副本并使用

Arrays.sort(theCopiedArrayName);
int HighScore = theCopiedArrayName[theCopiedArrayName.length];

排序后会得到最后一个数组值,使该值成为最大的。我希望这会有所帮助。

关于java - 我将如何为此程序创建最高分计数器以及将其放置在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29618540/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com