I'm making a program where I want the user to input a value into a variable. After it is inputted I want to check the value type, but I don't know how. It looks a bit like this:
import java.util.Scanner;
Scanner scanner = new Scanner(System.in);
int num1;
num1 = scanner.nextInt();
I want some way of checking the type of num1, so that I can make sure the user has inputted a usable value i.e. to make sure they haven't inputted a string such as "qwerty" into the integer variable, so that I can go on to catch the error if they have, rather than end up with a java.util.InputMismatchException. I've tried:
if(num1 instanceof java.lang.String)
but it doesn't fix the error and it doesn't work for integers either.
Any ideas on how to fix this?