gpt4 book ai didi

java - Java编译错误

转载 作者:行者123 更新时间:2023-12-02 11:15:32 24 4
gpt4 key购买 nike

当我尝试编译此代码时,我总是会遇到编译错误。代码如下。

import java.util.Scanner;

public class BaseballPitcher
{
private final int MAX_GAMES = 15;
private gamesPitched[];
private int totalGames;
private int totalRuns;
private float totalInnings;
private double ERA;

public BaseballPitcher()
{
gamesPitched = new GamePitched[];
}
public void inputGameData()
{
Scanner input = new Scanner (System.in);

do
{
System.out.printf ("How many games will you enter (up to %d): ", MAX_GAMES);
totalGames = input.nextInt();

if (totalGames <= 0 || totalGames > MAX_GAMES)
{
System.out.printf ("Error: You may only enter up to %d games" + " - Please try again\n\n", MAX_GAMES);
}
} while (totalGames <= 0 || totalGames > MAX_GAMES);

for (int x = 0, x < totalGames, x++)
{
gamesPitched[x] = new GamePitched();
gamesPitched[x].inputGame();
}
}
}

我收到的编译错误是:
[Please list your compile error or errors].

为什么会出现编译错误?

最佳答案

看来您有一个名为GamePitched的自定义类。您的数组gamesPitched[]可能应该是这种类型的数组,但是您已经声明了没有类型的数组。试试private GamePitched[] gamesPitched;
您的循环中只有语法错误-,应该是;,Java将该Java分隔为for循环中的子句。

您应该阅读stacktrace中提供的错误。即使您是Java的新手,它们也具有描述性,可以帮助您确定问题出在哪里(并经常提出解决方案)。

关于java - Java编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21469774/

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