Assignemnt #125: SummingThreeNumbersFromAnyFile
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: SummingThreeNumbersFromAnyFile
/// File Name: SummingThreeNumbersFromAnyFile.java
/// Date Finished: 2/22/2016
import java.util.Scanner;
import java.io.File;
public class SummingThreeNumbersFromAnyFile
{
public static void main(String[] args) throws Exception
{
Scanner key = new Scanner(System.in);
String fileName;
System.out.print("What file would you like me to read from? ");
fileName = key.next();
Scanner fileIn = new Scanner(new File(fileName));
int num1 = fileIn.nextInt();
int num2 = fileIn.nextInt();
int num3 = fileIn.nextInt();
int sum = num1 + num2 + num3;
System.out.println("\nReading numbers from file...");
Thread.sleep(400);
System.out.println(num1 + " + " + num2 + " + " + num3 + " = " + sum + "\n");
}
}
Picture of the output