The blog gives you idea of testing and automation testing example of selenium webdriver,SQl and Jmeter, you see the basic example of selenium web driver and get idea how to do automation testing,

Swap Of two Variable without use of Third Variable

Swapping of Two variable with out using third variable, this question is asked so many times in interview,

Concept and login behind this is very simple

1) Take two variable and assign value to them
2) Add value of both variable
3) Minus value of one variable from above added variable value

Below is the code of swap variable -:

public class swap {

static int x =10;
static int y= 20;

public static void main(String[] args)
          {

System.out.println("Value of X Before swap :-" + x );

System.out.println("Value of Y Before swap :-" + y );
x=x+y;
-- Swapping of variable logic
y=x-y;
x=x-y;

System.out.println("Value of X after swap :" + x );

System.out.println("Value of Y after swap :" + y );

}


                         }


OUTPUT :

X=20
Y=10

No comments

Post a Comment

Powered by Blogger.