I appreciate Keller trying to help earlier but that code is only good for the length of the string and not the number of integers.
Anyway, I need to basically rewrite the ArrayList method. I can't seems to get the addMethod code worked out.
I really only need someone to help me out with the concept and not the accual code.
So far the user it prompted with a JOptionPane.showInput... and I take that string, pass it into a new scanner and try to use a .hasNext to count the number of integers in the string. it doesn't do the count, the method code goes as follows:
java Code:
// find how many integers are in the string
int index = 0;
while (console.hasNext()) {
index++;
}
// create a new array with the index that is counted in the loop above
int[] array = new int[index];
int i = 0;
// loop through the string again and assign each integer to the array
while (console.hasNextInt()) {
array[i] = console.nextInt();
}
The first count "index" it not counting in that while loop and I do not know why. Any ideas? If you have a better idea to do this I would appreciate it.