我正在爲一個任務做一個java程序,其中一個例外是用戶不能輸入一個不存在的行或列的值。即,如果電路板是5x7並且用戶輸入了值爲10的列,則屏幕將打印「錯誤:無效列」。然而,我不確定如何做這個最後的例外,我需要今天提交它。如果有人可以幫助,我會非常感激!這裏是我的makeGuess()函數代碼:戰列艦遊戲例外
public void makeGuess(){
//guesses is for keeping track of your guesses
boolean cont=true;
int rowGuess;
int columnGuess;
do{
System.out.println("Enter a row to guess >");
rowGuess = (input.nextInt()-1);
if(rowGuess<=0){
System.out.println("You did not enter a positive Integer.Please try again");
cont=false;}
else{
cont=true;}
}
while (cont==false);
do{
System.out.println("Enter a column to guess >");
columnGuess = (input.nextInt()-1);
if(columnGuess <=0){
System.out.println("You did not enter a positive integer.Please try again");
cont=false;
} else{
cont=true;
}
}while(cont==false);