【发布时间】:2018-12-23 00:41:22
【问题描述】:
我正在制作一个基于文本的游戏,我的代码可以正常工作,直到我输入“为什么”时它不会打印“测试”。
System.out.println( "Fallout: Master's dialogue");
System.out.println(" ");
System.out.println( " So, what shall it be? Do you join the Unity or do you die here? Join! Die! Join! Die! ");
System.out.print( "> ");
Go = keyboard.nextLine();
if (Go.equalsIgnoreCase("join"))
{
System.out.println("Excellent. Your talents will be useful. But first you must tell me everything about your vault.");}
System.out.print("> ");
Look = keyboard.nextLine();
if (Go.equalsIgnoreCase("why"))
{System.out.println("TEST");}
System.out.print("> ");
Look = keyboard.nextLine();
}
【问题讨论】:
-
我觉得你应该写
Look.equalsIgnoreCase("why") -
为什么“加入”在上一个中起作用。
-
@Coder32 因为在
join中,您使用了正确的变量。Go,将只包含String“加入”。您需要使用Look变量 -
因为 Look 和 Go 是不同的变量
-
我的回答回答了你的问题吗?