Infosys

  www.infosys.com
  www.infosys.com

Interview Question

Senior Software Engineer Interview San Jose, CA

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

  variable.
Answer

Interview Answer

1 Answer

0

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 Question, Sign In with Facebook or Sign Up