45 90 40 30 42 95 64 47 23
14 80 30 84 24 49 16 10 20
I am beginner in Java OOP
This is the Txt file. I have to print sum of integers next to each line
and then find out the largest sum among them.
I can read the file
I tried by making each line as an String
I tried by making each line as an Int
but When I am making each digit of the line as an Int.
I couldn't able to figure out how to stop the program at the point where the column is ending so that I can print the sum and go to the next row.
import java.util.Scanner;
import java.io.*;
public class Asst1Problem2{
public static void main(String[] args){
int sum = 0;
int largestSum = 0;
String line = "";
try{
Scanner input = new Scanner(new File("integers2.txt"));
while(input.hasNextLine()){
line = input.nextLine();
System.out.println(line);
}
}
catch(FileNotFoundException fnf){
System.out.print("no file " + fnf);
}
}
}
Expecting to get the sum but i am not getting it right.