如果 PID 中的值已经存在于数组中,我如何要求用户重新输入?
例如:他输入A然后B,然后他再次输入A,那么他从最后输入的A将不会被接受,因为它已经存在。
int[] Process = {};
int NumberofProcess = 0;
String[] PID = new String[10]; //Proces ID
System.out.print("Enter a number of Process from 1 to 10 : ");
while(bError){
if(scan.hasNextInt()){
NumberofProcess = scan.nextInt();
}else{
scan.next();
continue;
}
bError = false;
}
//---------------- Ask for the user to input for the Process id AT and EX -------
for(int i=0;NumberofProcess > i;i++){
System.out.print("Please Enter a ProcessID " + (i + 1) + " : ");
PID[i] = scan.next();
}