This site requires JavaScript, please enable it in your browser!
Greenfoot back
someone1
someone1 wrote ...

2015/9/22

Separating float values in a txt file to find the avg

someone1 someone1

2015/9/22

#
I have another txt file which has one line a String, String, int, Float and Float. I want to find out the average of the last float on the line. For example say i have these two lines(the triple spacing represents the different data types), Trent Farmer 77 56.00 77.85, Harry Way 50 40.66 88.88 So i want to find the average of the numbers 77.85 and 88.88 But how would I do this if there are two floats on one line
danpost danpost

2015/9/22

#
The line would have to be split; then use parseFloat to convert the height and weight back to float values.
someone1 someone1

2015/9/24

#
Could you show me an example of this plz
danpost danpost

2015/9/25

#
someone1 wrote...
Could you show me an example of this plz
If 'line' was one entry in the file that was read back in, then the following would convert the height and weight back into floats:
String[] data = line.split("   ");
float height = Float.parseFloat(data[2]);
float weight = Float.parseFloat(data[3]);
You need to login to post a reply.