My method checks a user input if it is an integer. If it is, it prints a certain something in my code, if it is not an integer, it prints Invalid input. It works good except for when i input any integer ending with the letter "d", it accepts it as an integer. How do I fix this? Here's my code so far.
static boolean isNumber(String text) {
try {
Double.parseDouble(text);
return true;
} catch (NumberFormatException e) {
System.out.println("Input is non-numerical or incorrect.");
return false;
}
}
do {
System.out.print("Input loan principal amount : ");
input = s.nextLine();
} while (!isNumber(input));
double loan = Double.parseDouble(input);