I am trying to make a program opens a file called input.txt and sums all of the numbers in it along with counting the number of numbers.
So far i have
import java.util.Scanner; import java.io.*; import java.io.File; import java.io.IOException; public class test1 { public static void main(String[] args) throws IOException { String fileName = "input.txt"; Scanner fileScan = new Scanner(new File(fileName)); int sum = 0; int count = 0; File f = new File(fileName); Scanner scanFile = new Scanner (fileName); String line; while(scanFile.hasNext()) { line = scanFile.next(); count++; String integer; while (scanFile.hasNext()){ integer = scanFile.next();
Im really confused on how to add up integers from each line and save it to sum.