67 155
Assignments Done
99,4%
Successfully Done
In November 2018

Answer to Question #72899 in Java | JSP | JSF for Atif Haroon

Question #72899
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.
Expert's answer
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);

}
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions