java - Comparing 2 sets of integer values in 2 separate arrays -
i quite new java , have problem struggling work with. have 2 sets of numbers, stored in 2 separate arrays, representing lottery numbers. first set user numbers , second set numbers lottery webpage. have tried compare numbers position position in array unsure result leaves me correct number of matches , how can include match bonus ball, there 6 user numbers lottery, 7 lottery numbers in draw (6 numbers plus bonus number). have included code below:
// set array store numbers latest draw on lottery web page integer [] numbers = new integer [split.length]; int = 0; (string strno : split) { numbers [i] = integer.valueof(strno); i++; } (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 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 numbers"); usernumbers[pos]=keyboard.nextint(); pos++; } (int count: usernumbers) { system.out.println(count); } while ((pos < size) && (!found)) { if (usernumbers[pos] == numbers[0]) { found = true; system.out.println("you have matched 1 number"); //am wrong in saying //this? }else pos++; //am incrementing wrong counter , @ point //implement lottery counter? }//while if (!found) { system.out.println("you have not won time"); }else if (usernumbers[pos] == bonusball) { bonus = true; //i think wrong } //how go working out how many nos player has matched or how many //numbers theyve matched plus bonus?
first need method compare first 6 integers. order not matter need check if lotto number matches of numbers on ticket. simplest way loop within loop. each time check see if lotto number matches of 6 numbers, check next lotto number against 6 numbers. in event have match, increment counter int count = 0; // initialize outside loops if(mynum[x] == lottonum[x]){ count = count + 1; }
now know how many of first 6 numbers matches. create method see if bonus matches. bool bonushit; if(mynums[7] == lottonum[6]){ bonushit = true;} else{ bonushit = false;}
Comments
Post a Comment