jasonpogi1669

Add-Subtract-Multiply-Divide Functions: Method Overloading using Java

Feb 9th, 2021
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 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.  
  7. /**
  8.  *
  9.  * @author Jason
  10.  */
  11. class Arithmetic {
  12.     public int add (int a, int b) {
  13.         return a + b;
  14.     }
  15.     public int add (int a, int b, int c) {
  16.         return a + b + c;
  17.     }
  18.     public int add (int a, int b, int c, int d) {
  19.         return a + b + c + d;
  20.     }
  21.     public int subtract(int a, int b) {
  22.         return a - b;
  23.     }
  24.     public int multiply (int a, int b) {
  25.         return a * b;
  26.     }
  27.     public int multiply (int a, int b, int c) {
  28.         return a * b * c;
  29.     }
  30.     public int multiply (int a, int b, int c, int d) {
  31.         return a * b * c * d;
  32.     }
  33.     public int divide(int a, int b) {
  34.         return a / b;
  35.     }
  36. }
  37.  
  38. public class Main {
  39.     public static void main(String[] args) {
  40.         Arithmetic operation = new Arithmetic();
  41.         System.out.println(operation.add(1, 3));
  42.         System.out.println(operation.add(1, 3, 4, 5));
  43.         System.out.println(operation.multiply(2, 3, 4));
  44.         System.out.println(operation.multiply(1, 1));
  45.         System.out.println(operation.subtract(3, 1));
  46.         System.out.println(operation.divide(5, 2));
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment