Assignemnt #122

Code

/// Name: Sam menar
/// Period: 6
/// Program Name: Data From a File
/// File Name: DataFromAFile.java
/// Date Finished: 5/25/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, sum;

        System.out.print("Getting name and three 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();

        fileIn.close();

        System.out.println("done.");
        System.out.println("Your name is: " + name);
        sum = a + b + c;
        System.out.println(a + " + " + b + " + " + c + " = " + sum);
    }
}
        
        //using this scanner might cause a problem because if the file being used is written in 
        // the wrong format the program won't work.
    
            


    

Picture of the output

Assignment 13\