mercredi 27 juillet 2016

java - lotto read from text file

My console is supposed to read sets of numbers from a text file. The numbers in the file must be compared to 7 'lucky numbers'. The program must find out how many people had 3 matches, 4 matches, 5 matches, 6 matches and 7 matches with the 'lucky numbers', and the results must be printed at the end.

I dont know how to do the comparing between the numbers in the file and generating the 'lucky numbers'.

import java.io.*;
import java.util.*;
import java.util.Scanner.*;

public class Lotto {
    public static void main (String[] args) throws FileNotFoundException {

        Scanner lottoFile = new Scanner(new File("c:\\Exercises\\New Folder\\Lotto.txt"));
        ArrayList<Double> lotto = new ArrayList<Double>();

        while(lottoFile.hasNextLine()){
            String line = lottoFile.nextLine();

            Scanner scanner = new Scanner(line);
            scanner.useDelimiter(",");
            while(scanner.hasNextDouble()){
                lotto.add(scanner.nextDouble());
            }
            scanner.close();
        }

        lottoFile.close();

        System.out.println(lotto);
    }
}




Aucun commentaire:

Enregistrer un commentaire