所以,我正在创建一个基本的“拱廊”项目。我有传递到游戏中的卡片(方法)。我在 Card 类中创建了一个方法,以便能够选择用于游戏的卡片。public Card choosecard(Card firstCard, Card secondCard) { Scanner input = new Scanner(System.in); Card chosen = new Card(); boolean check = false; while(check == false) { System.out.println("What card would you like to use?\n 1. " + firstCard.name + "\n 2. " + secondCard.name); int answer = Integer.parseInt(input.nextLine()); if(answer == 1) { chosen = firstCard; check = true; } else if(answer == 2) { chosen = secondCard; check = true; } else { } } //while return chosen;创建此方法后,我尝试在此上下文中调用它:public static void terminal(Card card1, Card card2) { boolean loop = true; while(loop == true) { System.out.println("What would you like to do?\n1. Guess Game\n2. Transfer\n3. Prizes\n4. Cancel"); Scanner take = new Scanner(System.in); int answer = Integer.parseInt(take.nextLine()); switch(answer) { case 1: Game.GuessGame(Card.chooseCard(card1, card2)); } } 我认为这可能是因为我试图在另一个方法的参数中调用一个方法。所以我尝试从其他类调用它,但它仍然给出了找不到符号的错误。
2 回答
白板的微信
TA贡献1883条经验 获得超3个赞
Card.chooseCard(card1, card2)
意味着调用静态方法。你可能想声明chooseCard
为
public static Card choosecard(Card firstCard, Card secondCard)
潇潇雨雨
TA贡献1833条经验 获得超4个赞
public Card choosecard(Card firstCard, Card secondCard)
它不是静态方法。
Game.GuessGame(Card.chooseCard(card1, card2));
但是Card.chooseCard(card1, card2)
意味着你是静态调用它。
考虑将其设为静态或通过对象调用。
添加回答
举报
0/150
提交
取消