java异常练习:要求用户输入数字,捕获并处理用户输入错误的异常,给用户进行提示

package com.yichang;
import java.util.*;
public class Test2 {

    public static void main(String[] args) {
        
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入数字:");
        try{
        int a =sc.nextInt();
        System.out.println("输入的是:"+a);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            System.out.println("输入的类型错误"+ex.getMessage());
        }
    
    

    }

}

 

posted on 2016-05-27 20:23  煜渝  阅读(4876)  评论(0编辑  收藏  举报

导航