Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
import java.io.*;
class swap{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter 1st no: ");
int x=Integer.parseInt(br.readLine());
System.out.print("Enter 2nd no: ");
int y=Integer.parseInt(br.readLine());
System.out.println("\nNumbers Before Swapping:");
System.out.println("x = "+x);
System.out.println("y = "+y);
//Swapping Method 2
x = x^y;
y = x^y;
x = x^y;
System.out.println("\nNumbers After Swapping:");
System.out.println("x = "+x);
System.out.println("y = "+y);
}
}
Also you can use asm and stack:
- Yuri Fedoseev March 08, 2012push a
push b
pop a
pop b