Assignment #128
Code
/// Name: Matthew Lorence
/// Period: 5
import java.util.Scanner;
import java.io.File;
public class SummoningSeveral
{
public static void main(String[] args) throws Exception
{
Scanner keyboard = new Scanner(System.in);
int total= 0;
System.out.print( "Which file would you like to read numbers from: " );
String file = keyboard.next();
System.out.println("Reading numbers from \"" + file + "\"" );
Scanner fileIn = new Scanner(new File(file));
while ( fileIn.hasNextInt() )
{
int num = fileIn.nextInt();
System.out.print( num + " " );
total = total + num;
}
System.out.println();
System.out.println( "Total is " + total);
}
}
Picture of the output