Question: Consider the following method that is intended to swap the values of two integers: public static void falseSwap(int a, int b) { int temp =

Consider the following method that is intended to swap the values of two integers:

public static void falseSwap(int a, int b)
{
int temp = a;
a = b;
b = temp;
}
public static void main(String[] args)
{
int x = 3;
int y = 4;
falseSwap(x, y);
System.out.println(x + " " + y);
}
Why doesn’t the falseSwap method swap the contents of x and y?

Step by Step Solution

3.40 Rating (166 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public static void falseSwapint a int b int temp a a b b temp public static ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Concepts Late Objects Questions!