Hi, am trying input validation to this divisible number game. Am not sure where am getting it wrong, the input validation is not working.
package week06;
import java.util.Scanner;
public class DivisibleByX {
public static void main(String[] args) {
System.out.println("In this program, we will display a series of numbers divisible by an integer specified by the user.\r\n"
+ "You will ask the user for the starting number, the ending number and the integer to be considered..\n");
Scanner in = new Scanner(System.in);
Boolean playing = true;
boolean valid = true;
int num3 = 0;
int count = 0;
int num1 = 0;
int end = 0;
String input = "";
do {
System.out.println("Enter the starting number:\n");
input = in.nextLine();
num1 = Integer.parseInt(input);
System.out.println("Enter the ending number:");
input = in.nextLine();
int num2 = Integer.parseInt(input);
System.out.println("Enter the test number:");
input = in.nextLine();
num3 = Integer.parseInt(input);
count = num1;
end = num2 + 1;
do {
if( count % num3 == 0)
{
System.out.println(+count );
}
count = count + 1;
}while(count < end );
int xy;
do {
System.out.println("Would you like to play again?()Y/N");
String goAgain = in.nextLine();
String strup = goAgain.toUpperCase();
xy = 2;
if (!strup.equals("Y")) {
if (!strup.equals("N")) {
playing = true;
xy = 20;
try{
num1 = Integer.parseInt(input);
}catch(Exception e){
System.out.println("Invalid Response! Please answer with a 'Y' or 'N'.");
System.out.println("Thank you! ");
}
}else {
playing = false;
}
} else {
playing = true;
}
}while (xy > 10);
}while (playing == true);
in.close();
}
}