Respuesta :
Answer:
// here is the complete code in java to check the output.
import java.util.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
try{
int x=20,y=10;
System.out.println( x + "\t" + y );
swap( x, y );
System.out.println( x + "\t" + y );
}catch(Exception ex){
return;}
}
public static void swap( int a, int b )
{
if( a > b )
{
int temp = b;
b = a;
a = temp;
}
System.out.println( a + "\t" + b );
}
}
Explanation:
Here is "x" is initialize with 20 and "y" is with 10. The first print statement will print the value of "x" and "y" separated by a tab. Then it will the swap() method with parameter x and y.In the swap method, if first parameter is greater then it will swap the two value and the print statement will execute. It will print 10 and 20 separated by a tab. then in the main method, print statement execute And print the value of x,y as 20 and 10. Here value of x, y will not change by the method swap() because in java parameters are passed by value not by reference.That is why any change by swap() method will not reflect in the main method.
Output:
20 10
10 20
20 10