相关疑难解决方法(0)

如何让Java注册带空格的字符串输入?

这是我的代码:

public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  String question;
  question = in.next();

  if (question.equalsIgnoreCase("howdoyoulikeschool?") )
    /* it seems strings do not allow for spaces */
    System.out.println("CLOSED!!");
  else
    System.out.println("Que?");
Run Code Online (Sandbox Code Playgroud)

当我试着写"你喜欢学校怎么样?" 答案总是"阙?" 但它的工作正常,因为"howdoyoulikeschool?"

我应该将输入定义为除String之外的其他内容吗?

java string space

7
推荐指数
1
解决办法
9万
查看次数

标签 统计

java ×1

space ×1

string ×1