Short description: While loop always make the result not valid. Steps To Reproduce: Change to do while loop and change the stream. Actual Output: Always invalid Expected Output: Valid move will go on to show tips
Previous code: if (in.hasNextInt()) { start_x = in.nextInt(); start_y = in.nextInt(); } Point ps = new Point(start_x, start_y); StartMove start_m = new StartMove(ps); while (!start_m.isValidStartMove()) { // wait until the move is valid System.out.println("Not valid start move, please input again"); start_x = in.nextInt(); start_y = in.nextInt(); ps = new Point(start_x, start_y); start_m = new StartMove(ps); } Modified code: do { if (in.hasNextInt()) { start_x = in.nextInt(); start_y = in.nextInt(); } } while (start_x < 0 || start_x > 8 || start_y < 0 || start_y > 8); Point ps = Graph.getInstance().chessboard[start_x][start_y]; while (!StartMove.isValidStartMove(ps)) { // wait until the move is valid System.out.println("Not valid start move, please input again"); do { if (in.hasNextInt()) { start_x = in.nextInt(); start_y = in.nextInt(); } } while (start_x < 0 || start_x > 8 || start_y < 0 || start_y > 8);