public class Test {
public static void main(String[] args) {
int input;
Scanner sc = new Scanner(System.in);
while(true) {
System.out.println("input a number :");
try {
input = sc.nextInt();
if(input == -1)
break;
}catch (Exception e) {
System.out.println("!!!!");
}
}
}
}
public class Test {
public static void main(String[] args) {
String str;
Scanner sc = new Scanner(System.in);
while(true) {
System.out.println("input a number :");
try {
str = sc.nextLine();
int input = Integer.parseInt(str);
if(input == -1)
break;
}catch (Exception e) {
System.out.println("!!!!");
}
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |