62,612
社区成员
发帖
与我相关
我的任务
分享
import java.util.Scanner;
public class Excep{
static Scanner jd=new Scanner(System.in);
public static void main(String[] args){
while(true){
int on=0;//判断是否输入成功!
try{
int bb=jd.nextInt();
on=999;
}
catch(Exception e){
System.out.println("输入有误请重新输入");
}
if(on==999){//成功就跳出while循环
System.out.println("定义数字成功!");
break;
}
}
}
}
public class Test3 {
public static void main(String[] args) {
Scanner jd = new Scanner(System.in);
while (true) {
int on = 0;//判断是否输入成功!
try {
int bb = jd.nextInt();
on = 999;
} catch (Exception e) {
System.out.println("error");
}
if (on == 999) {//成功就跳出while循环
System.out.println("定义数字成功!");
}
}
}
}
import java.util.Scanner;
public class Excep{
public static void main(String[] args){
Scanner jd = null;
while(true){
int on=0;//判断是否输入成功!
try{
jd = new Scanner(System.in);
int bb=jd.nextInt();
on=999;
}
catch(Exception e){
System.out.println("输入有误请重新输入");
}
if(on==999){//成功就跳出while循环
System.out.println("定义数字成功!");
break;
}
}
}
}