below is the code:
Scanner scan = new Scanner(System.in);
String input = scan.next();
try{
double isNum = Double.parseDouble(input);
if(isNum == Math.floor(isNum)) {
System.out.println("Input is Integer");
//enter a double again
}else {
System.out.println("Input is Double");
//break
}
} catch(Exception e) {
if(input.toCharArray().length == 1) {
System.out.println("Input is Character");
//enter a double again
}else {
System.out.println("Input is String");
//enter a double again
}
}
taken from here: how to check the data type validity of user's input (Java Scanner class)
however, when i input 1.0 or 0.0, it is still considered as an integer, is 1.0 not considered a double?
Please help guys, thank you!