4. Write a program in Java to swap two numbers without using third variable.
For example if
a=5, and b=4 then after calling following function
Swap (int a, int b)
a=4 and b=5.
1
Expert's answer
2018-01-28T09:10:21-0500
public class Swap { public static void main(String[] args) { int a = 4; int b = 5; swap(a, b); }
public static void swap(int a, int b) { a=a+b; b=a-b; a=a-b; System.out.println("a="+a+" and b="+b);
Comments
Leave a comment