I'm in need of some assistance regarding comparing values from two arrays that are in separate class files.
I am writing a Lottery application (I am a student indeed!) and I have two arrays; one for the user inputted values, and one for the randomly generated winning numbers.
I must compare the two, and obviously, see if the user has won the lottery.
I believe I must use an accessor method for the user generated numbers to access an individual array index, and then search through the winning numbers and compare; however, what troubles me is accessing
the user generated numbers. What I think is correct is only producing "0".
Anyone have any ideas? I have searched the forum, but, it seems that it's rare to find others using separate class files so nothing applies.
It's kind of hard to help you if you don't post all the RELEVANT code. We certainly don't need to see hundreds and thousands of lines of code, but there needs to be enough that we can see what your code is REALLY doing. Even if you just post something like this:
we can see that the array might be filled.
Generally speaking, the easiest thing to do is put System.out.println() statements in your code. from your original snippet, i'd start by putting one in between lines 4 and 5, printing the value of iWinNum. Then also print winNumList[iWinNum]. You can then prove to yourself you are iterating through the winNumList correctly, that it contains the values you think it should, etc.
My guess is that some array ISN'T populated how you think it is. The only way to be sure is to print things out (or use a debugger, but that's a little more advanced).
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Giancarlo Marcelli wrote:the population of the array happens in another method, but i did not post the entire program at the time of the original post.
Shall I do that now?
I guess the most direct question is:
Is the array populated AFTER you do in this method? My guess is no - it is not. That you populate an array you store in the winNumList variable, then you call the method shown above and do This would create a NEW array, store it in the same variable (throwing the other array away to be garbage collected). You should not be creating a new array and re-assigning it if the array has already been assigned and filled in.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com