I am wondering how I can check if a user\'s input is a certain primitive type (I mean integer, String, etc... I think it\'s called primitive type?). I want a user to input s
Is this ok?
class Test
{
public static void main(String args[])
{
java.util.Scanner in = new java.util.Scanner(System.in);
String x = in.nextLine();
System.out.println("\n The type of the variable is : "+x.getClass());
}
}
Output:
subham@subham-SVE15125CNB:~/Desktop$ javac Test.java
subham@subham-SVE15125CNB:~/Desktop$ java Test
hello
The type of the variable is : java.lang.String