title: Display an Error for invalid input in JAVA
body: <p>I have written a JAVA program that takes input from the user and check if the user has entered the correct thing or not. I have taken the input from the Scanner class. If the user enters an invalid character like a String, I want to display 'Invalid Input'.</p>
  <pre><code>public class Main {
      public static void main(String[] args) {
          Scanner takeInteger = new Scanner(System.in);
          System.out.println(&quot;Enter a number&quot;);
          int enteredNumber = takeInteger.nextInt();
      }
  }
  </code></pre>