Assignment #122: Data From A File

Code

 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("Data.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 may not always be effective because it could read the wrong data from complicated text files.
    

Picture of the output