This should be a pretty simple question
So i created an array list(which is a float) and i have a text file that has 4 lines.
This is what is stored on the txt file(im focusing on the last numbers which are data type float)-
Mark Fitts 10 78.80
Harry Potts 15 60.89
Nancy Welling 13 56.55
Phil Wallberg 23 30.30
my array list name is called sumOfLastValue, now i already have a variable called lastVal which represents the the float values.
How would i go about trying to store all the float values and then adding them and displaying the result to the user
Right now this is what i have(This is not all of my code
All this code shows is the first float value on the first line 78.80
But i want to be able to sum all the float values, how would i do this
Thanks
1 2 3 4 5 6 7 8 | FileReader fr = new FileReader( "clients.txt" ); Scanner keyboard = new Scanner(fr); ArrayList<Float> sumOfLastValue = new ArrayList<Float>(); while (keyboard.hasNextLine()) { sumOfLastValue.add(lastVal); } System.out.println(sumOfLastValue); |