-1

How to find if a number or fraction is an integer in Java?

I did some research before but struggle to apply them. I want to do something like this:

if (x is int){
   //commands
}
lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
Skill HHY
  • 29
  • 6

1 Answers1

1

You should use something like this:

if((x%1)==0){
//do stuff
}

This checks to see if the decimal part of the number is zero.

TMcSquared
  • 107
  • 14