我几乎完成了这项任务,我只是不明白如何创建一个"最高分计数器"这将决定最高得分的比赛。这是我目前的计划
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;
}
}
我也在这一行得到了一个&#34;多个标记 - texansScore无法解析为 类型 - 缺少方法的返回类型 - 令牌上的语法错误&#34;,&#34;,删除它 令牌&#34;
上的错误 dterminePercent(texansScore, opponentsScore);
}
这是我的分配细节
*程序应打印:
a)休斯敦德州人赢得比赛的百分比,
b)休斯顿德州人的得分和对应的比赛数最高, c)所有比赛的最高总得分(德州人和对手的总和)以及相应的比赛数。*答案 0 :(得分:1)
要找到最高分,您可以随时使用分数数组的副本并使用
Arrays.sort(theCopiedArrayName);
int HighScore = theCopiedArrayName[theCopiedArrayName.length];
在排序后得到最后一个数组值,使该值最大。我希望我能以任何方式提供帮助。