Arianule
Arianule

Reputation: 9043

Comparing lottonumbers with winning lottonumber

I have to write an application where I retrieve a lotto numbers that I stored as strings in a database and compare them with the winning lotto number that was generated by the application itself. I am a bit stuck with this one.

I started of with retrieving the 6 lotto numbers from the database and adding it to an array list.

ArrayList<String> listTwo = new ArrayList<String>();


    ResultSet set = state.executeQuery("SELECT * FROM NumbersClients");
    while(set.next())
    {
        String numbers = set.getString(1);
                    listTwo.add(numbers);
    }

The numbers I generated randomly I saved in an ArrayList and then converted to an Integer array.

Integer[]entries = lottoDraw.toArray(new Integer[lottoDraw.size()]);

Any pointers perhaps as to how I can retrieve each individual lottodraw from 'listTwo' and compare them to the winning number('entries') and thus estblish 3,4,5 matches etc.

Thank you

Upvotes: 0

Views: 156

Answers (2)

John B
John B

Reputation: 32949

Since the list of lottonumbers in the DB is stored as Strings, convert the winning number to a String. Then just compare each element in the List against the winning String. You can iterate the list of possible winners, comparing each to the winning number and recording the winners in a list of indexes.

Since this is probably homework I won't post the code.

Upvotes: 1

GavinCattell
GavinCattell

Reputation: 3963

Why not store the numbers individually in the database. Then generate the winning numbers and query the database. E.g.

SELECT * FROM NumbersClients
WHERE no1 = ? AND no2 = ? AND no3 = ?
etc.

This way you avoid retrieving large amounts of irrelevant data

Upvotes: 2

Related Questions