我正在为一个任务做一个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);