Arithmetic Operations coderinme

Arithmetic Operations coderinme

Let us now Create a package called “Arithmetic” that contains methods to deal all arithmetic operations. Also, write a program to use the package.
addition () : a + b
Sub () : a – b
Mul () : a * b
Div () : a / b
Program:

class Arithmetic 
{
private double x,y;
public Arithmetic(double a,double b) 
{
x=a;
y=b;
}
public double Addition() 
{
return(x+y);
}
public double Sub() 
{
return (x-y);
}
public double Mul() 
{
return (x*y);
}
public double Div() 
{
return(x/y);
}
}
public class Q24 
{
public static void main(String[] args) 
{
Arithmetic a=new Arithmetic(45.56,3.4);
System.out.println("The Addition of Given two number is;"+a.Addition());
System.out.println("The Subtraction of Given two number is;"+a.Sub());
System.out.println("The Multiplication of Given two number is;"+a.Mul());
System.out.println("The Devision of Given two number is;"+a.Div());
}
}

For more programs on Java, visit our Java Archives

Arithmetic Operations coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.