【发布时间】:2012-05-20 20:10:51
【问题描述】:
我正在寻找一种将句子作为单个字符串输入的方法,我该怎么做? 我也可以只使用一个文件作为输入 (.txt),但我不知道如何处理它。
我基本上想忽略“空格”分隔符,需要帮助了解如何
到目前为止我所拥有的:
Scanner input = new Scanner(System.in);
Random randomGenerator = new Random();
int rand = randomGenerator.nextInt(10)+1;
System.out.print("Enter code to be encoded. End the text with a semicolon(;): ");
String in = input.next();
System.out.println();
System.out.println("Confirmation: Encode the following text? y to accept, n to decline");
System.out.println(in);
编辑: 添加了 src 我正在为我和一些朋友开发编码器,并且想一次做句子而不是一次做单词。是的,它们会以句号结尾。
【问题讨论】:
-
到目前为止你有什么?也许 nextLine 是您的解决方案,但我更愿意看到一些开始。
-
您对输入有什么限制?句号只在句末吗?每行输入只有 1 个句子吗?
标签: java string delimiter space