title: Take input and then cast into appropriate data type - Java
body: <p>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?</p>
  
  <pre><code>Scanner x = new Scanner(System.in);
  Object a = x.next();
  </code></pre>
  
  <p>here's my method for detecting the object type</p>
  
  <pre><code>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";
  
  
  }
  </code></pre>