Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How does Java judge whether the entered book is an integer?
How does Java judge whether the entered book is an integer?
In java, the Integer integer class is used for conversion. If there is no exception, it is an integer, as shown in the following example:

? /**

*? From the keyboard? Get? integer

*? @ Return

*/

Public? Static electricity int? getIntFromKeyboard()? {

int? num? =? 0;

Scanner? Input? =? New? Scanner (system. in);

System.out.println ("Please enter an integer:");

Try it? {

num? =? input . nextint();

}? Catch? (exception? e)? {

System.out.println ("The number you entered is not an integer!" );

Return? getintfromekeyboard();

}

Return? num

}