- public class AException{
- public static void main(String[] args) {
- Scanner scanner=new Scanner(System.in);
- boolean continueInput=true;
- do {
- try {
- int num1 = scanner.nextInt();
- String i=scanner.next();
- int num2=scanner.nextInt();
-
- int result = 0;
-
- switch (i.charAt(0)) {
- case '+': result = num1 +num2;
- break;
- case '-': result = num1-num2;
- break;
- case '*': result = num1*num2;
- break;
- case '/': result = num1/num2;
- }
- System.out.println(num1 + i + num2
- + " = " + result);
- continueInput=false;
- }
- catch (InputMismatchException ex) {
- System.out.println("Wrong Input: ");
- break;
- }
- } while (continueInput);
- }
- }
复制代码 只能输入整型数,假如输入3.4
怎样输出“Wrong Input:3.4”
就是要捕获输入错误的异常,想问怎样在“wrong input”后加上输入错误的数 赐教 谢谢 |