Scanner sc = new Scanner(System.in);
System.out.println("Enter whatever you want");
String st = sc.nextLine();
try {
    String d = String.valueOf(st);
    if (d == (String) d) {
        System.out.println((String) d);
    } else {
        System.out.println(d);
    }
} catch(Exception e) {
    System.out.println("integer");
}
When I try to execute this, it keeps printing "if" part even for integer and double.
 
     
     
     
     
    