Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to judge whether a number is an integer in java
How to judge whether a number is an integer in java
There are many methods, here are two examples:

Public? Static electricity Invalid? main(String[]? args){

int? Me? =? 1 1 1 1;

Double? f? =? 1 1 1. 1 1 1;

//Method 1

Bull? b? =? (int)I-I = = 0;

If (b){

system . out . println(" integer ");

} Otherwise {

System.out.println ("non-integer");

}

Bull? c? =? (int)f-f = = 0;

If (c){

system . out . println(" integer ");

} Otherwise {

System.out.println ("non-integer");

}

//Method 2

if(i==(long)i){

system . out . println(" integer ");

} Otherwise {

System.out.println ("non-integer");

}

if(f==(long)f){

system . out . println(" integer ");

} Otherwise {

System.out.println ("non-integer");

}

}