Assignment 122: Data From a File

Code

  ///Name: Ryan McAteer
  ///Period: 5
  ///Project Name: DataFromAFile
  ///File Name: Assignment122.java
  ///Date: 5/19/2016
    
import java.io.File;
import java.util.Scanner;

public class Assignment122 {

    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);
    }
    // Such scanner might cause a problem, b/c it does not wait until user inputs
    // values, but throws Exceptions in case of missing file/values within the file.
}


    

Picture of the output

This Should Work This Should Work