【问题标题】:Why isn't the text showing up? [closed]为什么文字不显示? [关闭]
【发布时间】: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 是不同的变量
  • 我的回答回答了你的问题吗?

标签: java text


【解决方案1】:

我假设 GoLook 是字符串变量。

在代码的开头,您读取用户输入并将其存储在Go

Go = keyboard.nextLine();

然后你检查了Go是否是join

if (Go.equalsIgnoreCase("join"))

这一切都很好。

然后,您第二次读取用户输入,并将其存储在Look

Look = keyboard.nextLine();

但是您错误地检查了Go

if (Go.equalsIgnoreCase("why"))

Go 未更改。 Go 仍然是“加入”,所以条件永远不会为真。

你应该检查Look

if (Look.equalsIgnoreCase("why"))

【讨论】:

    猜你喜欢
    • 2014-06-18
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    相关资源
    最近更新 更多