Assignemnt #122 Data From a File

Code

     ///Name: Prooz Fereydouni
    ///Period: 7
    ///Project Name: Data From a File
    ///File Name: DataFromAFile.java
    ///Date: 5/28/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();
        //using this type of Scanner required the code-writer's knowledge of the number of numbers and different elements in the .txt file.
        
        fileIn.close();

        System.out.println("done.");
        System.out.println("Your name is: " + name);
        sum = a + b + c;
        System.out.println(a + " + " + b + " + " + c + " + " + d + " = " + sum);
    }
}


    

Picture of the output

assignment122