In this tutorial, I will explain how to write a Java program to add two numbers without using the third variable.
In this program, I have declared two variables as X and Y with some values, after that, used plus operator to save both values and put the result in the first variable.
Copy the below Java program and execute it with the help of Java compiler to see the output of below program.
At the end of this tutorial, I have shared the real-time output.
public static void main(String args)throws Exception
int x = 15 , y = 10;
x = x+y;
System.out.println("\nSum of two numbers:"+ x);
Sum of two numbers: 25
Tags: addition of two number without using addition variable, sum of 2 num without temp variable, sum of 2 numbers without temp variable, sum of mumbers without using 3rd variable, temp variable non usage program of sum of 2 numbers