Asignment: #122 Importing Data From Files
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: DataFromFile
/// File Name: DataFromFile.java
/// Date Finished: 5/22/2016
import java.io.File;
import java.util.Scanner;
public class DataFromFile {
public static void main(String[] args) throws Exception {
String name;
int a, b, c, d, sum;
System.out.print("Getting name and four numbers from file.....");
Scanner fileIn = new Scanner(new File("name-and-numbers.txt"));
name = fileIn.nextLine();
a = fileIn.nextInt();
b = fileIn.nextInt();
c = fileIn.nextInt();
d = fileIn.nextInt();
fileIn.close();
System.out.println("done.");
System.out.println("Your name is: " + name);
sum = a + b + c + d;
System.out.println(a + " + " + b + " + " + c + " + " + d + " = " + sum);
}
// This form of a scanner could be erranous due to it not waiting for user inputs.
// throws Exceptions is used in case of missing file/values within that particular file.
}
Picture of the output