Assignment #122

Code

/// Name: Jonathan Stine
/// Period: 5
/// Program Name: Data From a File
/// File Name: DataFile.java
/// Date Finished: I have no idea, honestly.
    
    import java.io.File;
    import java.util.Scanner;
    
    public class DataFile {
    
        public static void main(String[] args) throws Exception {
    
            String name, comment;
            int a, b, c, d, sum;
    
            System.out.print("Getting name and three numbers from file.....");
    
            Scanner fileIn = new Scanner(new File("DataFile.txt"));
    
            name = fileIn.nextLine();
            a = fileIn.nextInt();
            b = fileIn.nextInt();
            c = fileIn.nextInt();
            d = fileIn.nextInt();
    
            fileIn.close();
    
            System.out.println("finished.");
            System.out.println("Your name is: " + name);
            sum = a + b + c + d;
            System.out.println(a + " + " + b + " + " + c + " + " + d + " = " + sum);
            //This kind of Scanner could be an issue because one piece of information cannot be accessed independently from the others.
        }
    }

    
 
    

Code Output