import java.util.Scanner;


public class TryScanner {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try{
            System.out.println("input int:");
            Scanner scanner=new Scanner(System.in);
            int i=scanner.nextInt();
            System.out.printf("%d\n",i);
        }catch(java.util.InputMismatchException e)
        {
            System.out.println(e.toString());
            System.out.println(e.getMessage());
        }
        System.out.println("exit...");

    }

}
input int:
qq
java.util.InputMismatchException
null
exit...
public class ErrorExceptionDemo {

    /**
     * @param args
     */
    public static void main(String[] args) {
        int i=2;
        try{
            for(int j=-1;i<3;j++)
            {
                int k=i/j;
                System.out.printf("%d\n",k);
            }            
        }catch(java.lang.ArithmeticException e)
        {
            System.out.printf("%s\n",e.getMessage());
            System.out.printf("%s\n",e.toString());
        }


    }

}

 

相关文章:

  • 2021-11-02
  • 2021-09-27
猜你喜欢
  • 2022-12-23
  • 2021-08-19
  • 2021-10-19
  • 2021-11-29
  • 2022-12-23
  • 2021-09-16
  • 2022-01-09
相关资源
相似解决方案