what i need to do is generate skydiving formations using ararys to store the formations numbers (which i generate using the class RANDOM)... so, i generate a number and store it in the array and then when another number is generated is compared with the values inside the array so there are not repetitions during the 10 rounds i have to generate... I think my problem is in the giveRandomNumber method because i'm getting repetitions... my method equalValue() is working properly from tests I've been doing in other program, so, id like to get some help with this :( i don't know exactly what to do right now cuz I'm not a programmer and i'm desperate :(

NOTE: others parts and method of the program are working pretty fine...

Re: Comparing array values with int's

Firstly you can make the equalValue more efficient by exiting the loop (or returning) as soon as it finds a duplicate value. As it is if you find the first number is a duplicate you still go and test all other nine values which is pointless.

Next your do loop in the giveRandomNumber method is a little hinky. Your condition is !isUsed. Imagine if the new formation is not in the array, equalValue returns false, ! false is true therefore your loop goes around again when it shouldn't and I imagine it doesn't go around again when it should.

Re: Comparing array values with int's

Imagine your array (at some point) contains [4,1,3,0,0,0,0,0,0,0]
You then generate the number 7 and store it in formation.
The number 7 is then stored in the array: [4,1,3,7,0,0,0,0,0,0]
That last line of code then says go to position 7 in the array and store the value there in the variable called formation. So the number 0 gets stored in formation. For what purpose?

Re: Comparing array values with int's

Re: Comparing array values with int's

You have commented out the calls to the giveRandomNumber method and are generating the random numbers in the main method. Looks like you need to step away from the keyboard, think about things, sketch out your ideas on paper and then go back and tidy up your code.