Java Program to swap 2 numbers using third variable, Write an application for swapping values of two variable using third variable
Program
class swap
{
public static void main(String args[])
{
int no1,no2;
no1 = Integer.parseInt(args[0]);
no2 = Integer.parseInt(args[1]);
Logic L=new Logic();
L.swapping(no1,no2);
}
}
class Logic
{
public void swapping(int n1,int n2)
{
int t; //Third Variable
System.out.println("No1 is : " + n1);
System.out.println("No2 is: " + n2);
t = n1;
n1 = n2;
n2 = t;
System.out.println("After Swapping..........");
System.out.println("No1 is : " + n1);
System.out.println("No2 is: " + n2);
}
}
No comments:
Post a Comment