Re: help with this program

Posted 28 March 2010 - 06:29 AM

well this is not much you have written... make some effort!
here are couple of things to think of:
1. use a Scanner Object to get user's input
2. have a method that check if an inputted number is already exists in the array.

Re: help with this program

Posted 28 March 2010 - 07:16 AM

well the "Asking for numbers" should also be inserted to the for loop block.
but just a thought, why are you using swing's JOptionPane and a Scanner Object for an input?
you can do all the coding just in the console, or just in swing.
anyways, here is how the code should be updated,:

hint for the part of non duplicate numbers:
for every new inputted number, go over the already inputted numbers in the array.
if the number is not already in, add it. else, post an error messege and ask for a new input.

Re: help with this program

Posted 28 March 2010 - 09:26 AM

if you declare an array of 10 int values declare it as:
int[] digits = new int[10];
array's indexes are numbers between 0 - length - 1.
in your case 0 - 9 (which is 10 values).
declaring it as you did (int[9] will create an array of 9 int values (indexes of 0 - 8).

again, if you use swing's JoptionPane, why also get input from the console?
first decide what you prefer. Console, or JOptionPane.
in case of using the console do it as:

notice that when using a JOptionPane, no Scanner Object is needed. you get the input through the JOptionPane.
also note that you have to parse the returned value of the JOptionPane, as it returns a String Object, and you want int values.
make sure that when inputting numbers you input ONLY int values, or else you will get an exception.