/** * @author lautturi.com * Java example: Check if a number is an integer or not */ import java.util.*; public class Lautturi { public static void main(String[] args) { int num = 3; if (num == Math.floor(num)) { System.out.println("the number "+num+" is an integer"); } double db = 3.14; if (db != Math.floor(db)) { System.out.println("the number "+db+" is not an integer"); } } }
output:
the number 3 is an integer the number 3.14 is not an integer