My problem with this code that I've written it only checks the existing number. I can't create another array to and compare them or check them. It cannot be done because my instruction explicitly asked us to use only one array. I have the assignment pretty much wrapped up the only problem is if you enter in the same number it will get put in the indices anyhow. meaning I type 11 it enters it in then I type 11 again, it says hey that's already there re-enter another number I type 11 again and well it enters 11 anyhow
Check out my code, advice is welcome. I don't want to have to use a trigger either to make this work.
In your 2nd for iterator, you should add check-- as below:
for( int check = 0; check < arrayNumbers.length ; check++)
if( arrayNumbers[check] == number)
System.out.println("Repeat numbers, try again");
number = input.nextInt();
hey i was doing pretty much the same problem earlier today. It was in an exercise from the book Java How to Program, is this where you got it from?
Do you want it to check against all the numbers in the array? If so have you considered using a boolean variable to indicate whether it's already there? You could change the boolean variable to true if the value is already in the array.
Joined: Feb 13, 2010
So would i be right in saying that if the number is in the array it asks you to enter another then it carries on with the for loop where it left off, therefore not checking the array indexes it has already checked? Because it should check them again.
This is the first time i've ever attempted to actually help someone as i'm still very new to java so sorry if my answer completely sucked! haha
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