Interview Question

Senior Software Engineer Interview San Jose, CA

switch value of variables a and b, without using 3rd


Interview Answer

1 Answer


int var1=100, var2=200;
System.out.println("Before Swapping "+var1+", "+var2);
var1 = var1 + var2;
var2 = var1 - var2;
var1 = var1 - var2;
System.out.println("After Swapping "+var1+", "+var2);

Kitu on Apr 13, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.