集册 Java实例教程 整数除法,无异常处理。

整数除法,无异常处理。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

536
整数除法,无异常处理。

import java.util.Scanner;


public class Main

{
/** from 
n o w j a   v  a . c o m - 时  代  Java**/

   // demonstrates throwing an exception when a divide-by-zero occurs

   public static int quotient(int numerator, int denominator)

   {

      return numerator / denominator; // possible division by zero

   }


   public static void main(String[] args)

   {

      Scanner scanner = new Scanner(System.in); /*N  o w  J a v a . c o m 提供*/


      System.out.print("Please enter an integer numerator: ");

      int numerator = scanner.nextInt();

      int denominator = 0;


      
展开阅读全文