I'm making a numbrosia puzzle for one of my classes. The problem that I'm having is trying to find some way to tell the user to follow instructions if an integer isn't entered. I can do it if the number is bigger than expected but not if its a letter or anything else. My guess is that it starts around where it says "int i = scan.nextInt();". I can also catch if the user doesn't input a correct move command. input.txt is just where I have the numbers for the puzzle. Also I didn't want to type all my methods like RU, RD, plusRow, etc. because I already wrote too much in my opinion ha Any help is appreciated. Thanks in advance.
import java.io.*; import java.util.Scanner; public class Numbrosia { static int [][] gameBoard = new int[5][5]; public static void main(String[] arg){ Scanner fileReader = null, scan = null; //Scanner scan = new Scanner(System.in); try{ fileReader = new Scanner(new File("input.txt")); scan = new Scanner(System.in); } catch (Exception e){ System.out.println(e); } for(int i = 0; i < 5; i++) //reading game board for(int j = 0; j < 5; j++) gameBoard[i][j] = fileReader.nextInt(); while(true){ showBoard(); System.out.println(""); System.out.println("Input number from 1 to 5: "); int i = scan.nextInt(); System.out.println("Input move command: "); String moveName = scan.next(); try{ if(moveName.equals("rl")){ RL(i-1); } else if(moveName.equals("rr")){ RR(i-1); } else if(moveName.equals("ru")){ RU(i-1); } else if(moveName.equals("rd")){ RD(i-1); } else if(moveName.equals("+r")){ plusRow(i-1); } else if(moveName.equals("-r")){ minusRow(i-1); } else if(moveName.equals("+c")){ plusColumn(i-1); } else if(moveName.equals("-c")){ minusColumn(i-1); } else{ System.out.println(""); System.out.println("Please follow instructions"); System.out.println(""); } } // In case user inputs # greater than 5 catch(Exception x){ System.out.println(""); System.out.println("Please follow instructions"); System.out.println(""); } } } }