import java.io.*;
public class Swapwithouttemp {
public static void main(String[] args) throws IOException
{
System.out.println("Enter first number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int x=Integer.parseInt(br.readLine());
System.out.println("Enter second number");
BufferedReader brr=new BufferedReader(new InputStreamReader(System.in));
int y=Integer.parseInt(brr.readLine());
new swap(x,y);
}
}
class swap
{
swap(int a, int b) throws IOException
{
System.out.println("Before swapped values a= "+a+"\tb= "+b );
a=a+b;
b=a-b;
a=a-b;
System.out.println("After swapped values a= "+a+"\tb= "+b );
}
}
public class Swapwithouttemp {
public static void main(String[] args) throws IOException
{
System.out.println("Enter first number");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int x=Integer.parseInt(br.readLine());
System.out.println("Enter second number");
BufferedReader brr=new BufferedReader(new InputStreamReader(System.in));
int y=Integer.parseInt(brr.readLine());
new swap(x,y);
}
}
class swap
{
swap(int a, int b) throws IOException
{
System.out.println("Before swapped values a= "+a+"\tb= "+b );
a=a+b;
b=a-b;
a=a-b;
System.out.println("After swapped values a= "+a+"\tb= "+b );
}
}
Comments
Post a Comment
Share this to your friends