Work in HR? Unlock Free Profile

Infosys Senior Software Engineer Interview Question

I interviewed in San Jose, CA and was asked:
"switch value of variables a and b, without using 3rd variable."
Add Tags [?]

Part of a Senior Software Engineer Interview Review - one of 1,938 Infosys Interview Reviews

Answers & Comments

of 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

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.