Addition program

Addition program

in Java | Python | C++

Java code :

Method - 1

public class Main{
    public static void main(String[] args){
        int a = 5;
        int b = 10;
        int c  = a + b;
        System.out.println("Addition of a and b is = " + c);
    }
}

Explanation :

Step 1: first we need to create the main method.

Step 2: then inside the main class we need to initialize a, b, c variables

Step 3: first we need to give values to the a and b value variables.

Step 4: we need to do the sum of a and b by using the operator +.

Step 5: After doing the sum we need to store the value in the c variable and print it to the screen using the system. out.println()

Method 2: Without using a third variable.

public class Main{
    public static void main(String[] args){
        int a = 5;
        int b = 10;
        System.out.println("Addition of a and b is = " + (a+b));
    }
}

Python code:

a = 10
b = 5
c  = a + b
print("Addition = " , c)

C++ code:

#include<iostream>
using namespace std;

int main(){
    int num1 = 5;
    int num2 = 10;
    int c = num1 + num2;
    cout << "Addition = " << c;
}

Output:

Did you find this article valuable?

Support Smart Cookie ๐Ÿช by becoming a sponsor. Any amount is appreciated!

ย