I have a rather silly question but I couldn't find a fix anywhere. I have a scanner set up that prints lines that are in appropriate format. Here is my while loop within that program:
while (fileScan.hasNextLine()){
String line = null;
line = fileScan.nextLine();
String[] element = line.split (":");
if(line.matches("\\w+\\s?\\w+?\\s?\\w+?\\s[:]\\s\\w+\\s?\\w+?\\s?\\w+?\\s[:]\\s\\d+\\s[:]\\s\\d+")){
count++;
System.out.println(element[0]+"["+element[2]+"]\t"+"|"+element[1]+"["+element[3]+" ]");
} else {
invalidLines++;
System.out.println("Line declined.");
}
}
What would I need to do in order to keep adding all the values of element[2] (assuming they are all strings, I do understand that converting them to int is necessary) and print a single line at the end with a total sum of added element[2]'s.
If you could just simply point me in the right direction I would highly appreciate it.