【问题标题】:when finding a specific word and breaking当找到一个特定的词并打破
【发布时间】:2016-02-18 04:25:06
【问题描述】:

我正在扫描来自用户的输入字符串。当用户在字符串中输入#END 命令时,程序将中断并显示输出。我该如何克服这个问题?

例如;

注意记笔记的方式。例如,我可以把#END 在这里,它不会保存其余的。

输出:

注意记笔记的方式。例如,我可以把

【问题讨论】:

  • 你能告诉我们一些你已经尝试过的代码吗?

标签: java string find break word


【解决方案1】:

最简单的方法是

  String input = "Pay attention to how notes are taken. For instance, I can put #END here, and it won't save the rest.";

  String [] out = input.split ("#END");

  System.out.println (out[0]);

如果来自用户使用Scanner 类。

【讨论】:

  • 它必须来自用户作为输入
  • 我已经在我的答案中添加了一些,但我不会为你编写整个代码。
  • @ScaryWombat Scanner scan = new Scanner(System.in); String input = scan.nextLine(); 好了。
猜你喜欢
  • 2019-06-12
  • 2023-03-15
  • 2022-11-17
  • 2014-08-13
  • 2021-11-26
  • 1970-01-01
  • 2011-11-11
  • 2010-12-22
  • 1970-01-01
相关资源
最近更新 更多