-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
  • 13,596
  • 5
  • 44
  • 76
Skill HHY
  • 29
  • 6

1 Answers1

0

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
  • 97
  • 13