Suppose i have a text file that has a number code and a string label on each line:
0102 Apple Banana Code
0203 Pear Watch Time
0405 Java Computer Pen
0607 Car Bike Drive
How could i print the sum of the non zero numbers in the front and the first two words of each line? Assuming that the numbers are always 4 digits and words are separated by a single space from the number and in between the words. For example I would get:
3 Apple Banana
5 Pear Watch
9 Java Computer
13 Car Bike
I have tried to initialize this but i have no idea where to go from here
FileReader fr = new FileReader(fileName);
BufferedReader inFile = new BufferedReader(fr);
String[][] words = new String[100][];
String line;
int size = 0;
while((line = inFile.readLine()) != null) {
words[size++] = line.split(" ");
}
inFile.close();