/* related posts with thumb nails */

Create a package called “Arithmetic” that contains methods to deal with all arithmetic operations. Also, write a program to use the package.:

Note: First create a directory by name “Arithmetic” and move to that directory, create the following file and compile the file in the same directory.

package arithmetic;

public class MyMath

{

public int add(int x,int y)

{

return x+y;

}

public int sub(int x,int y)

{

return x-y;

}

public int mul(int x,int y)

{

return x*y;

}

public double div(int x,int y)

{

return (double)x/y;

}

public int mod(int x,int y)

{

return x%y;

}

}

Note: Move to parent directory, write the following file and execute it.

import arithmetic.*;

class Test

{

public static void main(String as[])

{

MyMath m=new MyMath();

System.out.println(m.add(8,5));

System.out.println(m.sub(8,5));

System.out.println(m.mul(8,5));

System.out.println(m.div(8,5));

System.out.println(m.mod(8,5));

}

}

/* Output: */

13

3

40

1.6

3

Related Topics:

0 comments:

Post a Comment