Program to implement arithmetic functions.

/* Write a class to implement the following simple arithmetic operations:
(a). ADDITION  (b). SUBTRACTION  (c). MULTIPLICATION  (d). DIVISION
*/

import java.io.*;
class test
{     static double result;
static double addition(double x, double y)
{
result=x+y;
return(result);
}

static double subtraction(double x, double y)
{
if(x>y)
result=x-y;
else
result=y-x;
return(result);
}

static double multiplication(double x, double y)
{
result=x*y;
return(result);
}

static double division(double x, double y)
{
result=x/y;
return(result);
}
public static void main(String[] asd)throws IOException
{
BufferedReader obj= new BufferedReader( new InputStreamReader(System.in));
String num;
System.out.print("Enter the first number:: ");
num=obj.readLine();
double x= Double.parseDouble(num);
System.out.print("Enter the second number:: ");
num=obj.readLine();
double y= Double.parseDouble(num);
System.out.println("Choose One of the operation written bellow:: ");
System.out.println("1. ADDITION");
System.out.println("2. SUBTRACTION");
System.out.println("3. MULTIPLICATION");
System.out.println("4. DIVISION");
System.out.print("Enter your choice::");
num=obj.readLine();
int n= Integer.parseInt(num);
if(n==1) addition(x,y);
if(n==2) subtraction(x,y);
if(n==3) multiplication(x,y);
if(n==4) division(x,y);
System.out.println("Result= "+result);
}
}
Advertisements

2 thoughts on “Program to implement arithmetic functions.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s