SumSeveral

Code

import java.io.File;
import java.util.Scanner;

public class SumSeveral {

    public static void main(String[] args) throws Exception {
        
        Scanner keyboard = new Scanner(System.in);

        String name;
        int a, b=0, c, sum=0;

        System.out.println("Getting name and three file.....");
        System.out.println("1. 4nums.txt, 2. 5nums.txt, 3. 6nums.txt (type the name) " );
        name = keyboard.next();

        Scanner fileIn = new Scanner(new File( name ));
        while(b != 3 )
        {
        a = fileIn.nextInt();
        
        System.out.print( a + " " );
        
        sum=a+sum;
        b= b+1;
        }
        fileIn.close();
        
        System.out.println( " " );
        
        System.out.println( sum );
        
    }
}

SumSeveral

Assignment 128