Assignemnt #125 Summing Three Numbers From Any File
Code
import java.util.Scanner;
import java.io.File;
public class SummingThreeNumbersFromAnyFile
{
public static void main(String[] args) throws Exception
{
Scanner keyboard = new Scanner(System.in);
String fileName;
System.out.print("Which file would you like to read numbers from: ");
fileName = keyboard.next();
Scanner fileIn = new Scanner(new File(fileName));
int a = fileIn.nextInt();
int b = fileIn.nextInt();
int c = fileIn.nextInt();
int sum = a + b + c;
System.out.println("\nReading numbers from file...");
Thread.sleep(400);
System.out.println(a + " + " + b + " + " + c + " = " + sum + "\n");
}
}
Picture of the output