Assignment #128

   ///Name: Sam Wilson
   ///Period: 6
   ///Program Name: Summoning Several Numbers From Any File
   ///File Name: summonfile.java
   ///Date Finished: 6/1/16
    
    
 
    import java.io.File;
    import java.util.Scanner;
    
    public class SummingSeveralNumbers
    {
        public static void main(String[] args) throws Exception
        {
            Scanner keyboard = new Scanner(System.in);
            
            String file;
            int total = 0;
            
            System.out.println();
            System.out.print( "Which file would you like to read numbers from? " );
            file = keyboard.next();
            System.out.println( "Reading numbers from \"" + file + "\"... " );
            System.out.println();
            
            Scanner fileReader = new Scanner(new File(file));
            
            while (fileReader.hasNext())
            {
                int x = fileReader.nextInt();
                System.out.print( x + " " );
                total = x + total;
            }
            
            System.out.println();
            System.out.println( "Total is " + total );
            
            fileReader.close();
        }
    }  
  
    
    

Picture of the output

Assignment #128