不输入整数会报错:
import java.util.Scanner;
public class PrintInt {
public static void main(String[] args) {
String a,b;
Scanner scan = new Scanner(System.in);
while(true){
System.out.println("输入第一个整数 : ");
a = scan.next();
System.out.println("输入第二个整数 :");
b = scan.next();
try{
System.out.println(Integer.parseInt(a));
System.out.print(Integer.parseInt(b));
}catch(NumberFormatException e) {
System.out.println("请输入整数!");
}
}
}
}