Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package testy;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author bartl
  13. */
  14. public class Divide {
  15. public static double div(double a, double b) {
  16. double result = 0;
  17. String sA= Double.toString(a);
  18. String sB= Double.toString(b);
  19.  
  20. try {
  21. if (b == 0)
  22. throw new DivideByZeroException(sA,sB);
  23.  
  24. result = a / b;
  25. return result;
  26.  
  27. } catch(DivideByZeroException ex){
  28. System.err.println(ex.getMessage());
  29.  
  30. }
  31. return result;
  32. }
  33.  
  34. public static void main(String[] args) throws DivideByZeroException {
  35. Scanner scanner = new Scanner(System.in);
  36. System.out.println("Hello, I can calculate the number of times one number is contained within the other.\nPlease type in the divident: ");
  37. Double divident = scanner.nextDouble();
  38. System.out.println("OK good, now type in the divisor: ");
  39. Double divisor = scanner.nextDouble();
  40. double result = div(divident, divisor);
  41. System.out.println("The quotient is: " + result);
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement