Assignment #122 and Data from a File
Code
/// Name: Ali Kurland
/// Period: 6
/// Program Name: Data from a File
/// File Name: DataFromAFile.java
/// Date Finished: 5/9/2016
import java.io.File;
import java.util.Scanner;
public class DataFromAFile {
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 type of scanner might cause a problem because only the numbers or strings
*that are specifically designated in the program can be taken from the file. To include
*new numbers, strings, etc. from the file, the program has to be compiled again.
*/
Picture of the output