计算机杂谈

Java 03

2020-04-19  本文已影响0人  IT界汤哥看世界

import java.util.Scanner;

public class HelloJava 

{    public static void main(String args[])

    {    Scanner sc=new Scanner(System.in);

         System.out.println("first:");

         double a=sc.nextDouble();

         System.out.println("secend:");

         double b=sc.nextDouble();

    try

    {    double i;    i = a / b;

        if (b == 0)

        {    throw new Exception ("not0");    }

        System.out.println ("print:" + i);

    }

    catch (Exception e)

    {    e.printStackTrace ();    }

    }

}

   if (b == 0)

        {    throw new Exception ("not0");    }

这里是除零判断。

上一篇 下一篇

猜你喜欢

热点阅读