-1

I need help with something that can help me check if an int is a decimal. Something like:

if(variable == decimal){ //assuming the variable was entered by a user
    System.out.println("This number is a decimal.");
} else 
    System.out.println("This number is an integer.");
}
A. Wang
  • 1
  • 3

1 Answers1

1

If your "variable" value is a double then :

return Math.floor(variable) == variable;

Will return true if "variable" is an Integer.