I'm working on a very simple tax calculator in java to see where my skills are at after some basic lessons, and I have the basic functionality down but I'm trying to make the calculator able to deal with an error without crashing. Here's what my code looks like:
import java.util.Scanner;
public class Application {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter the principle");
float principle = scanner.nextFloat();
System.out.println("Your total with tax is: " + principle * 1.07);
So I run my code and it works out properly adding in 7% tax to whatever the principle entered is, but the program crashes when a letter or anything that isn't a number is entered. Ideally, I'd like to have it display something like "Please enter a number" if anything other than a number is entered. How should I go about doing this?