Assignment #128

Code

    
    ///Name: Cody Swain
    ///Period: 6
    ///Project Name: SummingSeveralNumber
    ///File Name: SummingSeveralNumber.java
    ///Date: 6/3/16
    
    
    
    import java.util.Scanner;
    import java.io.File;
    
    public class SummingSeveralNumber {
            
        public static void main(String[] args) throws Exception {
                
            Scanner kb = new Scanner(System.in);
                
            System.out.println("Which file would you like to read numbers from: ");
            String file = kb.next();
            System.out.println("");
                
            while (file.equals("4nums.txt") || file.equals("5nums.txt") || file.equals("6nums.txt") || file.equals("7nums.txt")) {
                    
                Scanner reader = new Scanner(new File(file));
                int total = 0;
                    
                while (reader.hasNext()) {
                        
                    int a = reader.nextInt();
                        
                    System.out.print(a + " ");
                        
                    total = total + a;
                }
                
                    System.out.println("Total: " + total);
                    System.out.println("");
                    System.out.println("Which file would you like to add from?");
                    System.out.print("> ");
                    file = kb.next();
                    System.out.println("");
            }
        }
    }

            


    

Picture of the output

Assignment 128