I am working on a program that will ask users for an integer and then another and put them as graph points. It will then tell them the distance between them. The user must input an integer or press "Q" to exit. If it is anything else (not an integer or the letter "Q"), it will tell them that is incorrect and to please try again. I thought this is how I could accomplish that but it returns the error cannot find symbol
. Help is appreciated greatly!
import java.util.Scanner;
public class PointCheck{
public static void main(String[] args){
try {
System.out.println("Welcome");
System.out.println("To quit at anytime please type \"Q\". Enter point:");
char Q = 'Q';
char q = 'q';
Scanner scan = new Scanner (System.in);
input = scan.next();
while (input.hasNext()) {
if (input.hasNextInt()) {
System.out.println("Int input");
}
else if (input.equals("Q")) {
System.out.println("Exiting");
}
/*else {
System.out.println("You did not enter a valid value. Please enter a number or \"Q\" to quit.");
}*/
}
}
catch(Exception e){
System.out.println("Exiting Program.");
}
}
}
If I don't comment out the last else statement it just defaults to that and loops my error message forever.