Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package testy;
- import java.util.Scanner;
- /**
- *
- * @author bartl
- */
- public class Divide {
- public static double div(double a, double b) {
- double result = 0;
- String sA= Double.toString(a);
- String sB= Double.toString(b);
- try {
- if (b == 0)
- throw new DivideByZeroException(sA,sB);
- result = a / b;
- return result;
- } catch(DivideByZeroException ex){
- System.err.println(ex.getMessage());
- }
- return result;
- }
- public static void main(String[] args) throws DivideByZeroException {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Hello, I can calculate the number of times one number is contained within the other.\nPlease type in the divident: ");
- Double divident = scanner.nextDouble();
- System.out.println("OK good, now type in the divisor: ");
- Double divisor = scanner.nextDouble();
- double result = div(divident, divisor);
- System.out.println("The quotient is: " + result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement