Using functions SWAP two numbers taken as input from Command Line arguments in Java.
Language : Java
Related : Swap using Call by Reference and Call By Value
[sourcecode language='java']
//Using Command line to Swap two numbers using a function
class Swap
{
public static void main(String args[])
{
int a=Integer.parseInt(args[0]);
int b=Integer.parseInt(args[1]);
System.out.println(“\nOriginal Values”);
System.out.println(“a = “+a+ ” b = “+ b);
swap(a,b);
}
static void swap(int x, int y)
{
int temp=x;
x=y;
y=temp;
System.out.println(“\nSwap Function Called”);
System.out.println(“x = “+x+ ” y = “+ y);
}
}
[/sourcecode]






