I am quite new to java and have this problem that I am struggling to work with. I have 2 sets of numbers, stored in two separate arrays, representing lottery numbers. The first set is the user numbers and the second set is the numbers from the lottery webpage. I have tried to compare the numbers position by position in the array but I am unsure as to what result leaves me with the correct number of matches and how I can include a match with the bonus ball, as there are 6 user numbers for the lottery, but 7 lottery numbers in the draw (6 numbers plus a bonus number). I have included my code below:
// set up an array to store numbers from the latest draw on the lottery web page
Integer [] numbers = new Integer [split.length];
int i = 0;
for (String strNo : split) {
numbers [i] = Integer.valueOf(strNo);
i++;
}
for (Integer no : numbers) {
System.out.println(no);
}
Element bonusElement = firstLottoRow.child(3);
Integer bonusBall = Integer.valueOf(bonusElement.text());
System.out.println("Bonus ball: " + bonusBall);
//Elements elementsHtml = doc.getElementsByTag("main-article-content");
final int SIZE = 7;
//array to store user numbers
int [] userNumbers = new int[SIZE];
boolean found = false;
int pos = 0;
int search = 0;
int searchPos=-1;
boolean bonus = false;
int lottCount;
while (pos<SIZE)
{
System.out.println("enter your numbers");
userNumbers[pos]=keyboard.nextInt();
pos++;
}
for (int count: userNumbers)
{
System.out.println(count);
}
while ((pos < SIZE) && (!found))
{
if (userNumbers[pos] == numbers[0])
{
found = true;
System.out.println("You have matched one number"); //am i wrong in saying //this?
}else pos++; //am i incrementing the wrong counter and at what point do i //implement the lottery counter?
}//while
if (!found)
{
System.out.println("You have not won this time");
}else if (userNumbers[pos] == bonusBall)
{
bonus = true; //i think this is wrong too
}
//how do i go about working out how many nos the player has matched or how many //numbers theyve matched plus the bonus?