Can anyone help me with this? or alter the code of mine when it comes to the user Input
here's the block of code of mine
public int Remove(int i, Briefcase c[], String[] m) {
int nChoice = 0;
System.out.print("\tPlease remove " + i + " cases: ");
nChoice = input.nextInt();
if (c[nChoice] == null) {
System.out.println();
System.out
.println("\tYou already entered that digit choose again\n");
Remove(i, c, m);
} else {
System.out.println("\tI'm " + m[nChoice]
+ " You just removed case # " + nChoice);
System.out.println("\t|" + nChoice + "| contains $"
+ c[nChoice].getAmount() + "\n");
}
return nChoice;
}
what this basically do is when you enterd an index of an array and that array is null it will printout a message saying that you already entered a number. else it rwill return your choice. but the problem is when I enter a number larger than the bounds of an array it gives me and out bounds exception and also when I enter a letter or a negative number it also gives me an exception. soo how will I solve this? I want to keep on getting the users input after that the error is thrown he will not leave this block of code unless he entered the right number already, if I say right number, I mean not out of bounds and all of those other exceptions will be thrown.
Sorry for my bad english