mercredi 28 octobre 2015

Reading a file's ints but skipping non int strings

I'm a serious noobie here trying to learn this shit. I am in college and this is an assignment so I dont want any serious code written, just a push in the right direction.

I have an input txt file with one word per line. Some are numbers, the rest are words. I can not figure out how to record just the numbers as ints and the rest as strings!

I tried the following:

while(stream.hasNextInt()){
month = stream.nextInt();
}

The first variable in the txt file is an int and then there are like 10 lines of strings before another int. But it will only store the first value as an int and then terminates the loop, rather than eventually store the next int!

Aucun commentaire:

Enregistrer un commentaire