我正在做的只是练习测试,我认为它做得很好,但我得到了,我认为是一个范围问题。它说,“团队无法解决变量类型”,我尝试了一些我认为会修复它的东西,但它们没有用。这是代码:
import java.util.Scanner; public class fundamentalsofgame {
public String hteam;
public String cteam;
public String teams(String hometeam, String compteam){
String hteam = hometeam;
String cteam = compteam;
return "The teams are " + hteam + " vs " + cteam;
}
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
String hometeam;
String awayteam = "New England Cheatriots";
hometeam = scanner.next();
teams team = new teams(hometeam, awayteam); //error
}
}
答案 0 :(得分:0)
teams
是一种方法,而不是您的类名,而是fundamentalsofgame
。因此,您需要创建fundamentalsofgame
的对象并在其上调用teams
方法。改变这个:
teams team = new teams(hometeam, awayteam); //error
到
fundamentalsofgame obj = new fundamentalsofgame();
fundamentalsofgame.teams(hometeam, awayteam);