Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. class Calculator {
  2. public int add(int x, int y) {
  3. return x + y;
  4. }
  5.  
  6. public int sub(int x, int y) {
  7. return x - y; // could be negative, but that's ok
  8. }
  9.  
  10. public int mul(int x, int y) {
  11. return x * y;
  12. }
  13.  
  14. public int div(int x, int y) {
  15. // there's something wrong here.
  16. try {
  17. return x / y;
  18. }
  19. catch (Exception err) {
  20. System.out.println(err);
  21. System.out.println("You cannot divide by zero!");
  22. System.exit(1);
  23. }
  24. return -1; // this will never be reached
  25. }
  26.  
  27. public void print_menu() {
  28. String menu = "0) Exit\n1) Add\n2) Sub\n3) Mul\n4) Div\n5) Factorial";
  29. System.out.println(menu);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement