Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. package w18comp1008s3;
  2.  
  3. import java.util.InputMismatchException;
  4. import java.util.Scanner;
  5.  
  6. /**
  7. *
  8. * @author Abhishek
  9. */
  10. public class ExceptionHandling
  11. {
  12. public static int quotient(int numerator, int denominator)
  13. {
  14. return numerator/denominator;
  15. }
  16.  
  17. public static void main(String[] args)
  18. {
  19. try{
  20. Scanner keyboard = new Scanner(System.in);
  21. System.out.print("Enter the numerator: ");
  22. int numerator = keyboard.nextInt();
  23.  
  24. System.out.print("Enter the denominator: ");
  25. int denominator = keyboard.nextInt();
  26.  
  27. System.out.printf("Result: %d/%d=%d %n", numerator, denominator, quotient(numerator , denominator));
  28. }
  29. catch(InputMismatchException mismatchException)
  30. {
  31. System.out.print("Only Integers are Accepted.");
  32. }
  33. }
  34.  
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement