大致如下:
import java.util.Scanner;
public class testDigit {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
while (!(str.matches("\\d+"))) {
System.out.println("输入的" + str + "不是数字,请重新输入");
str = sc.nextLine();
}
System.out.println("输入的" + str + "是数字");
}
}