Nikhil Shah
Newbie
- Jun 30, 2022
- 7
- 1
In Java, how can I "return" the swapped value of two integers from a function?
Is it necessary to return an object of some kind, containing the swapped values for a and b, because Java is always pass-by-value? I'm reading this article about swapping two numbers in Java from https://www.scaler.com/topics/swapping-of-two-numbers-in-java/. Also, do I really need the three lines I already wrote in this method?
Code:
class Solution{
static List<Integer> get(int a,int b)
{
a=a+b;
b=a-b;
a=a+b;
//**What will be the return statement?**
}
}