Computer Science, asked by dishasloth, 1 month ago

Write a program in Java to accept two numbers and exchange them without using 'third variable' and 'addition-subtraction operators'.​

Answers

Answered by rishabh1999singhal
1

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