gpt4 book ai didi

Java:一个程序出错,但另一个程序没有错误。 "Illegal start or type"

转载 作者:行者123 更新时间:2023-12-02 04:27:36 25 4
gpt4 key购买 nike

标题很长..我知道...但无论如何...

出于某种奇怪的原因,我在一个程序中收到错误“类型非法开始”,但是当我将其与我之前编写的程序进行比较时。该错误不会显示在那里。由于某些奇怪的原因,在我现在编写的代码中。我也收到了“预期”错误。

我现在编写的代码是这样的

public class Hero {
public static Dice d = new Dice();
public String n;
public int s, p ,i;
public int currentHP;
public int maxHP = 100;
public int maxMP = 100;
public int maxSP = 100;

public Hero(String n, int s, int p, int i,){ //illegal start of type
this.n = n;
this.s = s;
this.p = p;
this.i = i;
this.currentHP = maxHP;
}
public int Attack(){
int damage;
damage = (p*s) + d.Stats();
}
//<identifier> expected

}

与我之前制作的程序相比

public class Character implements Arma {
public static Dice d = new Dice();
public String n;
public int s, p, i;
public int currentHP;
public int MP;
public int maxHP = d.Health();
public int maxMP = d.Health();

public Character (String n, int s, int p, int i){
this.n = n;
this.s = s;
this.p = p;
this.i = i;
this.currentHP = maxHP;
this.MP = maxMP;
}
public int attack()
{
int damage;
damage = ((s * p) + i) + d.Dice();
return damage;
}

我在角色中没有收到任何错误...这让我困惑不已...只是因为我还没有完成英雄的整个代码吗?但这没有意义,因为我制作时角色代码很好,那么为什么英雄代码会出现问题呢?

附注字符代码是我学习的时候写的。它;然而,这仍然完全是我的想法。 Hero 代码本质上只是重新格式化的副本。

P.P.S。 Arma 代码只是一个接口(interface),用于“升级”Character 类,以便它可以与我们必须在类里面编写的另一个代码并驾齐驱。它实际上除了提供角色代码武器之外什么也不做。

最佳答案

这里有一个拼写错误public Hero(String n, int s, int p, int i,)

看到 ,int i 之后删除它并更改为这个:

public Hero(String n, int s, int p, int i)

关于Java:一个程序出错,但另一个程序没有错误。 "Illegal start or type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37452892/

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