You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
836 B

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. import java.util.*;
  2. public class MathProblems
  3. {
  4. // Implement this method, which prompts the user for a and b, then divides a by b
  5. // and then calculates a % b. If the user enters an invalid type of input, or a
  6. // zero for the divisor, an Exception will be thrown, both of which need to be caught
  7. public void divide()
  8. {
  9. Scanner input = new Scanner(System.in);
  10. try
  11. {
  12. System.out.print("Enter a: ");
  13. int a = input.nextInt();
  14. System.out.print("Enter b: ");
  15. int b = input.nextInt();
  16. }
  17. catch(InputMismatchException ime)
  18. {
  19. }
  20. catch( )
  21. {
  22. }
  23. }
  24. public static void main( String[] args )
  25. {
  26. // Test it here in main, when ready
  27. MathFunctions functions = new MathFunctions();
  28. functions.divide();
  29. }
  30. }