0% found this document useful (0 votes)
66 views1 page

Exercise 2 Arithmetic Operations: Object Oriented Programming - Practical Exercise 2

This document provides an exercise to understand basic arithmetic operators in Java. It outlines steps to write a program that defines integer variables to store the result of addition, subtraction, multiplication, and division functions. The functions take integer parameters, perform the arithmetic operations, and return the result. The main function calls each function and prints the results to the console.

Uploaded by

Manish Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views1 page

Exercise 2 Arithmetic Operations: Object Oriented Programming - Practical Exercise 2

This document provides an exercise to understand basic arithmetic operators in Java. It outlines steps to write a program that defines integer variables to store the result of addition, subtraction, multiplication, and division functions. The functions take integer parameters, perform the arithmetic operations, and return the result. The main function calls each function and prints the results to the console.

Uploaded by

Manish Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Object Oriented Programming Practical

Exercise 2

Exercise 2

Arithmetic Operations

Objective: This exercise enables you to understand the basic arithmetic operators in Java. Procedure: This program prints the result of arithmetic operations on integer data types on the console. Algorithm: The algorithm for the program is given below: Step 1: Open a new text document on your desktop. Step 2: Type in the relevant code as given below: 2.1: Write a main function with appropriate declarations: int sum, diff, prod, quotient; //call the functions as shown below. sum = add(a,b); diff = sub(a,b); prod = mul(a,b); quotient = div(a,b); 2.2: declare functions as given below: int add(int a, int b); { return a + b;} int sub(int a, int b); { return a-b;} // check for the sign // of the resultant by using if statements to get a // positive or negative result. int prod(int a, int b); { return a * b); } int div(inta,int b); { return a/b or b/a as appropriate} Step 3: Print the results on the console.

Sikkim Manipal University

Page No.: 2

You might also like