我已经在这条线上发表评论了。为什么该行不接受另一个输入?然后不断重复,直到输入一个整数。
import java.util.*;
class ScanNumbers{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int[] NumberEntry = new int[6];
for (int i = 1; i < NumberEntry.length; i++){
boolean isInteger = false;
while (!isInteger){
try {
System.out.print("Entry " +i + "/5, enter an integer value: ");
NumberEntry[i] = scan.nextInt();
isInteger = true;
}
catch (Exception e){
System.out.print("Entry " +i + "/5, Please enter only an integer value: ");
NumberEntry[i] = scan.nextInt(); //Right here, I would like to ask again, why is this line not doing the job?
}
}
}
Arrays.sort(NumberEntry);
System.out.print("The max integer is: " + + NumberEntry[NumberEntry.length-1]);
}
}
我不能告诉它再试一次吗?
编辑1:哈哈,哦,天哪,谢谢,我删除了该行,但现在输出不断重复“输入1/5,输入一个整数值:”
编辑2:谢谢!现在工作正常!