I’m trying to extract the numbers individual lines from a text file and perform an operation on them and print them to a new text file.
my text file reads somethings like
10 2 5 2
10 2 5 3
etc…
Id like to do some serious math so Id like to be able to call upon each number from the line I’m working with and put it into a calculation.
It seems like an array would be the best thing to use for this, but to get the numbers into an array do I have to use a string tokenizer?
Obviously you don’t have to use an
int[] nums. You can instead doAlternatively, if you know the structure ahead of time to be all ints, you could do something like this:
It creates Integer objects which is less desirable, but isn’t significantly expensive these days. You can always convert it to an
int[]after you slurp them in.