异常处理 除数 圆

Posted wannengc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异常处理 除数 圆相关的知识,希望对你有一定的参考价值。

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");
    }
}

 

以上是关于异常处理 除数 圆的主要内容,如果未能解决你的问题,请参考以下文章

《C#零基础入门之百识百例》(二十)异常处理 -- 除数为0

sql server中除数为零的处理技巧

Python异常处理

Python中异常处理

python学习笔记(十五)异常处理

异常处理