Computer Science, asked by sanniaarora176, 2 days ago

Write a java program to swap two values without using a third variable.

Answers

Answered by anandsagar0006
2

Answer:

class demo {

public static void main(string arg[]) {

System.out.println("Before swapping");

int x = 10;

int y = 20;

System.out.println("value of x:" + x);

System.out.println("value of y:" + y);

system.out.println("After swapping");

x = x + y;

y = x - y;

x = x - y;

System.out.println("value of x:" + x);

System.out.println("value of y:" + y);

}

}

Similar questions