import java.util.Scanner;
public class Display2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("输入一个正整数:");
String a = null;
boolean b = true;
while(b){
a = sc.next();
if(a.matches("[0-9]+")){
System.out.println("是正整数。");
break;
}else{
System.out.print("输入错误,请重新输入:");
}
}
}
}
温馨提示:答案为网友推荐,仅供参考