package a1; import java.util.Scanner; public class Radius { public static double y(double r)throws Exception{ double s=0; if(r<=0){ throw new Exception(); } s=Math.PI; return s; } public static void main(String[] args) throws Exception { Scanner sc=new Scanner(System.in); System.out.println("输入圆的半径:"); int r=sc.nextInt(); double s=0; try { s=y(r); System.out.println("圆的面积"+s); } catch (Exception e) { if (e instanceof Exception){ System.out.println("参数错误"); r=sc.nextInt(); s=y(r); System.out.println("圆的面积"+s); } } } }
计算圆的面积,半径不能为零和负数
最新推荐文章于 2022-05-05 00:06:42 发布