> hi i need help comparing ten numbers given by the
> user and stored in the form of an array. the numbers
> cannot be repeated. thanks
Get user input:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html
Storing unique objects:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Set.html
After your set is of size 10, you can convert it to an array.
what i need to do is get the user to enter ten numbers without repeating any of the numbers. I can get the user to input the ten numbers using a 'for' loop and storing the numbers in arrays. What i cannot do is compare them so if any of them are the same the program sends an error message and asks the user to input the ten numbers again until non of the numbers given by the user are the same
Suppose you have already entered 3 numbers
Now you are entering a fourth. Can you think of any way to check if the 4th number matches any of the first three? Perhaps you could compare each of the three previous numbers one after the other with the fourth. If none of them match, well then the fourth number is ok and now you have a list of 4 numbers that are all different.
Does that give you any ideas?
> what i need to do is get the user to enter ten
> numbers without repeating any of the numbers. I can
> get the user to input the ten numbers using a 'for'
> loop and storing the numbers in arrays. What i cannot
> do is compare them so if any of them are the same the
> program sends an error message and asks the user to
> input the ten numbers again until non of the numbers
> given by the user are the same
It sounds like a job for Set. Check it out!
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Set.html#add(java.lang.Object)