我创建了以下石头、纸、剪刀游戏。我正在尝试创建一个名为“winner”的方法,它告诉用户谁赢得了比赛。我创建了一个变量“end”,它是方法“winner”的输出。当我执行 $System.out.println(winner(weapon, computerWeapon)) 时,它给了我一个编译错误。有人可以帮忙调试这个问题吗?我是java的新手。
错误:错误:无法从类型 Game 中对非静态方法 Winner(java.lang.String, java.lang.String) 进行静态引用
import java.util.Scanner;
public class Game {
String end;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String computerWeapon;
System.out.print("Human, choose your weapon: ");
String weapon = input.next().toLowerCase();
int randomNumber = (int)(Math.random()*(3));
if (randomNumber == 0) {
computerWeapon = "rock";
}
else if (randomNumber == 1) {
computerWeapon = "scissors";
}
else {
computerWeapon = "paper";
}
System.out.println("Computer chooses: " + computerWeapon);
System.out.println(winner( weapon, computerWeapon));
}
public static String winner(String weapon, String computerWeapon){
if (weapon.equals("rock")){
if(computerWeapon.equals("rock")) {
end= "Tie!";
}
else if (computerWeapon.equals("scissors")) {
end = "Human wins!";
}
else if (computerWeapon.equals("paper")) {
end= "Computer wins!";
}
}
else if (weapon.equals("paper")){
if(computerWeapon.equals("rock")) {
end= "Human wins!";
}
else if (computerWeapon.equals("scissors")) {
end= "Computer wins!";
}
else if (computerWeapon.equals("paper")) {
end= "Tie!" ;
}
}
else if (weapon.equals("scissors")){
if(computerWeapon.equals("rock")) {
end= "Computer wins!";
}
else if (computerWeapon.equals("scissors")) {
end= "Tie!";
}
else if (computerWeapon.equals("paper")) {
end= "Human wins!";
}
}
return end;
}
}
繁华开满天机
aluckdog
相关分类