Assignemnt #128 sum3.java
Code
/// Name: Boris Kazantsev
/// Period: 6
/// Program Name: sum3
/// File Name: sum3.java
/// Date Finished: 5/28/2016
import java.util.Scanner;
import java.io.File;
public class sum3{
public static void main(String[] args) throws Exception{
int score=0;
String fileName = "";
Scanner keyboard = new Scanner(System.in);
while (!fileName.equals("exit"))
{
System.out.print("File name: ");
fileName = keyboard.next();
if (!fileName.equals("exit"))
{
System.out.print("Loading data from \"" + fileName + "\".....");
Scanner fileIn = new Scanner(new File(fileName));
System.out.println("Done");
System.out.println("============================================");
while(fileIn.hasNext())
{
int num = fileIn.nextInt();
System.out.print(" "+num);
score += num;
}
fileIn.close();
System.out.println();
System.out.println(" Total: "+score);
}
}
}
}
Picture of the output