IO reading (java) -
if have loop so:
while(st.hasmoretokens() ) { array[i] = st.nexttoken(); array[(i+1)] = st.nexttoken(); i++; } will array[i] , array[i+1] end having same word or put 1 word in array[i] , next word in array[i+1]? i'm trying read in 2 words @ time until line runs out of words. thanks.
yes "will put 1 word in array[i] , next word in array[i+1]".
note nexttoken() returns next token st string tokenizer. careful nosuchelementexception - if there no more tokens in st tokenizer's string.
try this:
while(st.hasmoretokens() ) { array[i] = st.nexttoken(); if(st.hasmoretokens()) // check again whether next toaken available or not array[(i+1)] = st.nexttoken(); i++; }
Comments
Post a Comment