I have an arraylist of 50 RANDOM integers. I ask a user to remove a number and all occurences of that number are removed from the list. I did that using
while (randInts.contains(removeInt) )
{
if (randInts.get(i) == removeInt)
randInts.remove(randInts.get(i));
i++;
}
System.out.println("\n" + randInts.toString());
System.out.println("\n" + randInts.size());`
The other part of the problem is to prompt the user to enter another number. The removed number from above is inserted after each occurrence of the second prompted number. I am having issues with the second part as I keep getting IndexOutOfBoundsException.
System.out.println("\n Please enter another integer in 1...10: "); int insertAfterInt = input2.nextInt(); while (randInts.contains(insertAfterInt) ){ if (randInts.get(i) == insertAfterInt) randInts.remove(randInts.get(i)); } System.out.println("\n" + randInts.toString()); System.out.println("\n" + randInts.size());