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

标签 java counter

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

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/

相关文章:

java - 分析/优化谷歌应用引擎应用程序的最佳方式是什么?

Java:将直接 ByteBuffer 转换为 double[]

javascript - 如何创建一个计数器循环,该循环在单击提交按钮时启动并输出多行单词,每个单词前面有一个数字?

用于大小数字的 Javascript 计数器

javascript - onclick counter = array.length 不起作用

java - DynamoDBMappingException : no mapping for HASH key - even though I clearly mapped it

java - 如何模块化 A* 中的启发式(运行时启发式)

mysql - 如何在MySQL select中增加计数器但不在结果中显示(隐藏)它

javascript - 如何将数据保留在本地 html 文件 meme 奖励网页中以允许计数器永久保留?

java - 如何仅使用表格 :errors? 打印全局错误