If that is the contents of your "data.in", then you are passing in a String which cannot be parsed to a float. You need to skip a line each time because your program is catching "The first data value is" as float, when you think your getting "1066".
Its not an ideal solution, but you need to do a "inFile.readLine();" before you do your float parsing (where you would to another "indline.readLine()", and then again in the loop. [ April 16, 2005: Message edited by: Kashif Riaz ]
No, you must read two lines: skip the first, parse the second. Do this repeatedly.
The other option is to put the conversion into a try-catch block and ignore the line if it can't be parsed into a number. Put that inside the loop reading lines. This way your code will handle a file that isn't "text-num-text-num" but rather "text-num-num-text-num" or any other combination, but only if the assignment calls for it of course.
Also, why are you parsing the numbers as float when the file clearly has integers and you're casting the float to an int before adding to the sum anyway. You lose any decimal portion that may have been there, so why parse it as float in the first place?
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad: