Program #123

Code

   
    /// Name: Afaf Nabeeha
    /// Period: 7
    /// Program Name: Simple File Input
    /// File Name: Simple.java
    /// Date Finished: 3/8/2016 public class Simple

        import java.io.File;
        import java.util.Scanner;
        
        public class Simple {
        
            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);
            }
          }


             
    

Picture of the output

Assignment 123