import java.io.File;
import java.util.Scanner;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/*
 * TwoScannersTextFileExample.java
 *
 * Created on February 27, 2005, 1:51 PM
 */

/**
 *
 * @author Bill Kraynek
 */
public class TwoScannersTextFileExample {
    
    /** Creates a new instance of TwoScannersTextFileExample */
    public TwoScannersTextFileExample() throws Exception {
        // the file being read must be in the parent folder of the src folder
        Scanner fileScanner = new Scanner(new File("numbers.txt"));
        int sum = 0;           
        while( true ) {
            if( !fileScanner.hasNext() ) break;
            String nextLine = fileScanner.nextLine();
            Scanner lineScanner = new Scanner(nextLine);
            int firstNum = lineScanner.nextInt();
            int secondNum = lineScanner.nextInt();
            if( firstNum < secondNum ) {
                sum += secondNum;
            } else {
                sum += firstNum;
            } // end if
        } // end while
        JOptionPane.showMessageDialog(null,"The sum of the largest numbers is " + sum + ".");
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        new TwoScannersTextFileExample();
    }// end main
    
}

