Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Calculator {
- public int add(int x, int y) {
- return x + y;
- }
- public int sub(int x, int y) {
- return x - y; // could be negative, but that's ok
- }
- public int mul(int x, int y) {
- return x * y;
- }
- public int div(int x, int y) {
- // there's something wrong here.
- try {
- return x / y;
- }
- catch (Exception err) {
- System.out.println(err);
- System.out.println("You cannot divide by zero!");
- System.exit(1);
- }
- return -1; // this will never be reached
- }
- public void print_menu() {
- String menu = "0) Exit\n1) Add\n2) Sub\n3) Mul\n4) Div\n5) Factorial";
- System.out.println(menu);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement