【发布时间】:2012-07-12 18:51:13
【问题描述】:
这是我目前对这部分程序的了解;
String text = JOptionPane.showInputDialog("enter a sentence");
String newWord = "";
char space = '_';
int count = 0;
for(int i = 0; i < text.length(); i++)
{
int found = text.indexOf(space, i);
int start = found + 1; // start location of substring after a space
int end = text.indexOf(space, start); // end of word
count = end + 1;
}
while(count < text.length())
{
newWord[count] = text.substring(start, end);
count++;
}
System.out.println(newWord[count]);
【问题讨论】:
-
这对我来说就像是代码/作业转储。原始发帖人,请准确地告诉我们您遇到的问题,并尽快提出具体的可回答问题,否则此问题可能很快就会被关闭。
-
这是我尝试开始工作的方法的一部分。我想将一个句子分成单个单词并将这些单词放入一个数组中
-
它在什么方面没有达到你想要的效果?您究竟希望 SO 社区为您做什么? (我们不会做的一件事就是为你做作业。)
-
newWord不是一个数组,所以尝试用newWord[count]来解决它甚至不会编译... -
我不是要你帮我做作业,我是要你给我一些指导,说明它为什么不起作用以及我可以做些什么来使它起作用。
标签: java arrays substring indexof