Sum and Difference of two numbers – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Code Learning #JAVA#569 siteicon   siteicon   siteicon  

Sum and Difference of two numbers

Gives you understanding of declaration along with dynamic initialization

Learning Objectives

To learn java concepts related to :

  • Initializing variables dynamically.

Program Approach

The objective is to demonstrate the dynamic initialization and declaration of variables.

We will be firstly declaring two variables with their initial values. Then we will be initializing a third variable with the sum and the fourth variable with difference of the stored values.

Source Code

TC++ #569

Source Code

Run Output

The sum of two numbers is 60.
The difference of two numbers is 20.

Code Understanding

int sum=num1+num2;

In this line we have initialized the variable sum with the sum of the values stored in the variables num1 and num2.

int dif=num2-num1;

In this line we have initialized the variable dif with the difference of the values stored in the variables num2 and num1.


Suggested Filename(s): SumDifference.java



Share

admin| Created: 16-Aug-2016 | Updated: 21-Mar-2018|






Back