Help with looping logic
1. I am new to this forum, can someone let me know how I attach a code tag.
2. Im doing an exercise where I have to enter 20 values into an array . Each value I enter has to be different from a value previously entered value.If the value already exists in the array, the program should allow the user to put in a another value. I have been trying nested for loops but im just confused. Can someone help me on how to go about it ?
[442 byte] By [
nutojavaa] at [2007-10-2 4:37:29]

> 1. I am new to this forum, can someone let me know
> how I attach a code tag.
http://forum.java.sun.com/help.jspa?sec=formatting
> 2. Im doing an exercise where I have to enter 20
> values into an array . Each value I enter has to be
> different from a value previously entered value.If
> the value already exists in the array, the program
> should allow the user to put in a another value. I
> have been trying nested for loops but im just
> confused. Can someone help me on how to go about it ?
for (loop twenty times)
ask user for value
while (value is in the array) ask user for new value
insert value into array
next
to place code use [ code ] and [ /code ] minuse the spaces...
you can use a nested loop I guess if you just make it have an if statement that checks if the ArrayList contains the object. if it does have it go into a loop that aska for a different input and breaks only if the ArrayList doesn't contain the new input.