How to swap values between two variables without using a
third variable?

Answer Posted / shyam sundar baishya

How to swap two String values without using a
third variable?

In Java::
=========
String s1 = "Shyam Sundar Baishya" ;
String s2 ="Dilip Kumar";
System.out.println("Before swapping ............");
System.out.println("s3 == "+s1);
System.out.println("s4 == "+s2);
s1= s1+s2;
System.out.println("....................");
System.out.println("After swapping ............");
s2 = s1.substring(0,(s1.length()-s2.length()));
s1 = s1.substring(s2.length(),(s1.length()));
System.out.println("s3 == "+ s1);
System.out.println("s4 == "+ s2);

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

3. What is the difference between testing and Quality Assurance?

1483


Definition of Singleton Class? what is the Purpose of it? what is the advantage?

1590


in IT trend mantis meant what? how to know mantis in IT trends? detail description about mantis?

1647


how to data grid use in data bind?

1494


what is adodb??y it is used for connection of V.B and access??what is ado?dao?

1774






how do u handle table control inbdc explain the process in steps iwant the answer in urgent please forward this even i know how to explain there

1753


in network security,how we identified threat?some one say we found threat according to it's signature,but how we get signature or pattern of the virus?

1519


what are the things i had to say in personal introduction in hr round mail me to prasanna.1867@rediff.com

1681


what do u mean by tagging

1616


what is d main diff between the java and .net framework

1548


Difference between views and index in sas programming

1028


what is woransient key word? how it is used in java

1806


How to change the color of a cell or a row in a datagrid on mouse hover using javascript/.net

1534


hi i m deepak my shedule for NIC pi is 17 Apr please contact me if anybody has interview on same day or give me some idea who have faced

1560


can any method return type may be constructor , or that method name allow

1582