所以,我有一些相当简单的代码,但是在第二类中,两个方法都找不到name
. 这是一个简单的范围问题吗?
package rpg;
import java.util.Scanner;
public class Start {
static String name;
public static void main (String args[])
{
Engine test12 = new Engine();
name = test12.gameStart();
System.out.println("So, " + name + " it is!");
}
}
哪个调用这个类:
package rpg;
import java.util.Scanner;
public class Engine {
static boolean playerNameLike = false;
String name = (" ");
public String gameStart()
{
while (playerNameLike = false)
{
System.out.println("So, whats your name?");
Scanner gameStart = new Scanner(System.in);
name = (gameStart.next());
nameTest();
}
return name;
}
public boolean nameTest()
{
System.out.println("Does " + name + " sound good?");
System.out.println("(Y)es or (N)o?");
Scanner gameStart = new Scanner(System.in);
String yesNo = new String (gameStart.next());
if (yesNo.equals("Y"))
{
playerNameLike = true;
return playerNameLike;
}
if (yesNo.equals("N"))
{
playerNameLike = false;
return playerNameLike;
}
return playerNameLike;
}
}
有谁知道我做错了什么?