Java Program to add two numbers
- May 09, 2020
- by
Java Program to add two numbers
In this Java Program, we perform addition of two numbers.
Logic : int c = int a + int b
Step 1 : Take two numbers 5 and 15 and stored it in the variables named as num1 and num2 and create another variable named as sum.
Step 2 : Perform the addition of the two numbers by using the + operator and store the result of the addition in the variable named as sum.
Step 3 : Use the System.out.println method to display the result to the user.
Program:
public class AddTwoNumbers
{
public static void main(String[] args)
{
int num1 = 5, num2 = 15, sum;
sum = num1 + num2;
System.out.println("Sum of these numbers:"+sum);
}
}
Output :
Sum of these numbers: 20
For execution of the code to visit my YouTube channel.
https://youtu.be/MUjD5D2ZWmk


0 comments:
Post a Comment