Assignemnt #128 and Summing Several Numbers
Code
///Name: Daniel Tiffany-Appleton
///Period: 7
///Program Name: Summing Several Numbers
///File Name: SummingSeveralNumbers
///Date Finished: 3/30/16
import java.util.Scanner;
import java.io.File;
public class SummingSeveralNumbers
{
public static void main( String args[] ) throws Exception
{
Scanner keyboard = new Scanner(System.in);
System.out.print( "Which file would you like to read numbers from: ");
String file = keyboard.nextLine();
Scanner reader = new Scanner(new File( file ));
System.out.println( "Reading numbers from \"" + file + "\"");
System.out.println(" ");
int total = 1;
while( reader.hasNext())
{
int num = reader.nextInt();
System.out.print( num + " ");
total = total + num;
}
System.out.println(" ");
System.out.println("Total is " + total);
}
}
Picture of the output