Write a program in Java to accept two numbers and exchange them without using 'third variable' and 'addition-subtraction operators'.
Answers
Answered by
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
Math,
25 days ago
Social Sciences,
25 days ago
Hindi,
25 days ago
Business Studies,
1 month ago
Science,
1 month ago
Math,
8 months ago