Hello, this problem can be solved with the help of java regular expression features. First, use the Scanner instance object to get the next string, assuming that it is stored in String inputStr for the time being. A regular expression of type int can be represented by the following string:
String regStr = "^[+- "? [ 1-9][0-9]*$|^0$";
The following if statement can be used to judge integers:
if(inputStr.match(regStr)){
system . out . println(" integer ");
} Otherwise {
System.out.println ("non-integer");
}
Finally, I sincerely hope to learn something!