IO 读取 (java)
IO reading (java)
如果我有这样的循环:
while(st.hasMoreTokens() )
{
array[i] = st.nextToken();
array[(i+1)] = st.nextToken();
i++;
}
array[i] 和 array[i+1] 最终会有相同的词,还是将一个词放在 array[i] 中,下一个词放在 array[i+1] 中?我试图一次读 2 个单词,直到我的台词用完为止。
谢谢
是的 "will it put one word in array[i]
and the next word in array[i+1]
"。
请注意 nextToken()
returns 来自 st
字符串分词器的下一个分词。小心 NoSuchElementException
- 如果 st
分词器的字符串中没有更多的分词。
尝试这样的事情:
while(st.hasMoreTokens() )
{
array[i] = st.nextToken();
if(st.hasMoreTokens()) // check again whether the next toaken is available or not
array[(i+1)] = st.nextToken();
i++;
}
如果我有这样的循环:
while(st.hasMoreTokens() )
{
array[i] = st.nextToken();
array[(i+1)] = st.nextToken();
i++;
}
array[i] 和 array[i+1] 最终会有相同的词,还是将一个词放在 array[i] 中,下一个词放在 array[i+1] 中?我试图一次读 2 个单词,直到我的台词用完为止。 谢谢
是的 "will it put one word in array[i]
and the next word in array[i+1]
"。
请注意 nextToken()
returns 来自 st
字符串分词器的下一个分词。小心 NoSuchElementException
- 如果 st
分词器的字符串中没有更多的分词。
尝试这样的事情:
while(st.hasMoreTokens() )
{
array[i] = st.nextToken();
if(st.hasMoreTokens()) // check again whether the next toaken is available or not
array[(i+1)] = st.nextToken();
i++;
}