Assignment #125
Code
/*
jack newsom
period 5
program ThreeNumSum2
filename ThreeNumSum2.java
date completed 2/19/16
*/
import java.util.Scanner;
import java.io.File;
public class ThreeNumSum2 {
public static void main( String[] args ) throws Exception
{
Scanner user = new Scanner(System.in);
System.out.print("Which file would you like to read from: ");
String pullFrom = user.next();
Scanner fileReader = new Scanner(new File(pullFrom));
System.out.println("Reading numbers from file \"" + pullFrom + "\"" );
System.out.println("");
int num1, num2, num3, sum;
num1 = fileReader.nextInt();
num2 = fileReader.nextInt();
num3 = fileReader.nextInt();
sum = num1 + num2 + num3;
System.out.println(num1 + " + " + num2 + " + " + num3 + " = " + sum);
System.out.println("");
}
}
Picture of the output