标签:return func scanner sys lang UNC can oid tin
第一种
public static boolean func(String value) {
try {
Integer.parseInt(value);
return true;
} catch (Exception e) {
return false;
}
}
public static void main(String[] args) {
while (true) {
Scanner sc = new Scanner(System.in);
//調用方法
boolean s = func(sc.next());
if (s == true) {
System.out.println("输入的是数字");
} else {
System.out.println("输入的是不是数字");
}
}
}
第二種:
Scanner sc;
int i = 0;
do {
System.out.println("请输入VIP类型:\n1 一般類型\n2 超級VIP");
sc = new Scanner(System.in);
if (sc.hasNextInt()) {
i = sc.nextInt();
}
} while (i!=1||i!=2);
标签:return func scanner sys lang UNC can oid tin
原文地址:https://www.cnblogs.com/zhenqk/p/13252477.html