异常

package work;

import java.util.Scanner;

public class ExceptionTest {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double n1 = in.nextDouble();
        double n2 = in.nextDouble();
        double result;
        try{
            result = n1/n2;    
            System.out.println(result);
        }catch(ArithmeticException e){
            e.printStackTrace();
        }finally{
            System.out.println("finally");    
        }
        in.close();
    }

}package work;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Work2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double radius;
        try{
            radius = in.nextDouble();
            System.out.println(radius);
        }catch(InputMismatchException e)
        {
            System.out.println("您输入的数据有问题");
        }
    }
    }package work;

public class Person {
    private String name;
    private int age;
    private String id;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) throws IllegalArgumentException{
        if(id.length()!=18)
        {
            throw(new IllegalArgumentException());
        }
        this.id = id;
    }
}

posted @ 2019-06-05 15:22  赵奕龙  阅读(126)  评论(0编辑  收藏  举报