【发布时间】:2016-08-05 13:43:51
【问题描述】:
如何使用 for 循环将用户输入的单词与空格分开。
Scanner scan = new Scanner(System.in);
int i;
System.out.print("Enter a word > ");
String word = scan.next();
for (i = 0; i < word.length(); i++) {
System.out.print(word.charAt(i));
}
【问题讨论】:
-
你可以使用
System.out.print(word.charAt(i) + " "); -
你得到的错误是什么?什么不工作?
-
我没有收到错误消息,它只是不断打印单词,字母之间没有空格。