Assignment #128

Code

      /*
jack newsom
period 5
program SeveralSum
filename SeveralSum.java
date completed 2/22/2016
*/

import java.util.Scanner;
import java.io.File;

public class SeveralSum
{
    public static void main( String[] args ) throws Exception
    {
        Scanner userIn = new Scanner(System.in);
        
        System.out.print("Which file would you like to read numbers from? ");   
        String fileName = userIn.next();
        
        Scanner fileReader = new Scanner(new File(fileName));
        int x = 0;
        
        while(fileReader.hasNext())
        {
            
            int temp = fileReader.nextInt();
            x = x + temp;
            System.out.print( temp + " " );
            
        }
        
        System.out.println();
        System.out.println("Total is " + x );
    }
}
    

Picture of the output