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
|
Run Output
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
admin| Created: 16-Aug-2016 | Updated: 21-Mar-2018|