I have been trying to figure out how to add one number in an array to another number in an array. I parsed the numbers in a String into integers, and separated them by columns. Then, I added each column into an array.
What I would like to solve is how to add all the numbers in a column.
The numbers are from a text file.
// numbers.txt:
Bob, 100, 98, 95
Alex, 85, 90, 92
I already used bufferedReader and parsed the numbers, from String to int.
The challenge is adding the numbers by column.
For example, if there are 3 numbers in each array, I just want to add the first numbers in each array.
Q1 is [100, 98, 95] Q2 is [85, 90, 92]
Only 100 + 85 together.
Below are the codes that I have so far. Any help on how to proceed will be awesome! Thanks for your time.
int Q1 = Integer.parseInt(columns[1]);
int Q2 = Integer.parseInt(columns[2]);
ArrayList<Integer> Q1list = new ArrayList<>();
Q1list.add(Q1);
Q1list.add(Q2);
double total = 0.0;
for (int i = 0; i < Q1list.size(); i++) {
total += Q1list.get(i);
}
System.out.println(total);