I'm trying to make a method that takes input of any data type from user and then cast that input into a variable type. But my code always returns string type. any fix required?
Scanner x = new Scanner(System.in);
Object a = x.next();
here's my method for detecting the object type
public static String inputValidator(Object input)
{
if(input.getClass().getName().equals("java.lang.String"))
{
return "string";
}
else if(input.getClass().getName().equals("java.lang.Integer"))
{
return "integer";
}
return "nor";
}