异常处理 除数 圆

时间:2022-12-12 19:53:44
package bbb;
import java.util.Scanner;
public class ExceptionTste {
    public static void main(String[]args){
        int x,y;
        float sum = 0;
        System.out.println("请输入除数");
        Scanner x1=new Scanner(System.in);
        Scanner y1=new Scanner(System.in);
        x=x1.nextInt();
        y=y1.nextInt();
        try{
            sum=x/y;
        }catch(Exception e){
            e.printStackTrace();
        }
        finally{
            System.out.println(sum);
        }
        System.out.println("program over");
    }
    
}
package bbb;
import java.util.Scanner;
public class Yuan {
    public static void main(String[]args){
        double r,s=0;
        System.out.println("请输入圆的半径");
        try{
            Scanner r1=new Scanner(System.in);
            r=r1.nextInt();
            s=r*r*3.14;
        }catch(Exception e){
            e.printStackTrace();
        }
        finally{
            System.out.println(s);
        }
        System.out.println("program over");
    }
}