【发布时间】:2012-04-19 18:28:51
【问题描述】:
有没有办法创建某种类型的 For 循环来用空格分隔字符串? 到目前为止,我可以显示一个字符串并找出它有多少个字符。
import java.util.Scanner;
import java.lang.String;
public class Word{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int b;
String word;
System.out.println ("Enter a word: ");
word = scan.next();
b = word.length();
System.out.println (word);
System.out.println (b);
}
}
【问题讨论】:
-
为什么需要这样做?即您需要了解原理,还是需要完成工作?
-
您是否有要拆分的带有空格的字符串,或者您想通过插入空格来分隔字符串?
-
通过插入空格来分隔字符串,对不起。
-
你想在哪里插入空格?