gpt4 book ai didi

java - "Cannot find symbol: method damage(int)"

转载 作者:行者123 更新时间:2023-12-02 06:31:06 28 4
gpt4 key购买 nike

我收到以下错误:

C:\Users\[USER]\Desktop\Java\TextAdventure\TextAdventure.java:39: cannot find symbol

symbol : method damage(int)

location: class TextAdventure

out.println("you do "+damage(pS)+" damage");

public class TextAdventure{
public static int pS=0;
public static void main(String args[]){
Scanner reader=new Scanner(in);
while((pS>10) || (pS<1)){
out.println("\nEnter your strength attribute: ");
pS=reader.nextInt();
}//ask for strength, repeat if not between 1 and 10
out.println("you do "+damage(pS)+" damage");

具有 damage(int) 方法的 RandomDamage 类如下:

public class RandomDamage {
public static int damage(int x){
int dMult=(int)(Math.random()*11);
return dMult*x;
}
}

我是第一次使用 JCreator LE 的“项目”,所以我只是假设我不需要处理创建不同的包或任何东西。我在“Package Default”下有 RandomDamageTextAdventure

最佳答案

您必须指定类别。

out.println("you do "+ RandomDamage.damage(pS)+" damage");

如果不这样做,它将在当前类 TextAdventure 中查找方法 damage(int)

关于java - "Cannot find symbol: method damage(int)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20035658/

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