我对java很陌生,并且遇到了我正在努力解决的问题。我有 2 组数字,存储在两个单独的数组中,代表彩票号码。第一组是用户号码,第二组是来自彩票网页的号码。我试图在数组中逐个位置比较数字,但我不确定什么结果让我得到正确的匹配数以及如何将匹配与奖金球包括在内,因为彩票有 6 个用户号码,但抽奖中有 7 个彩票号码(6 个号码加上一个奖金号码)。我在下面包含了我的代码:
// 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?