Assignemnt #125 and Summing Three Numbers from any File
Code
/// Name: Brian Phillips
/// Period 5
/// Program Name: Summing Three Numbers from any File
/// File Name: SummingThree.java
/// Date Finished: 5/31/2016
import java.util.Scanner;
import java.io.File;
public class SummingThree
{
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