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

Answer Posted / gayitri91

import java.io.*;

class Swap_2_Strings
{
String s1,s2;
DataInputStream dis=new DataInputStream(System.in);


Swap_2_Strings()
{
try
{
int n,m;
System.out.println("Enter 2 strings");
s1=dis.readLine();
s2=dis.readLine();
n=s1.length();
m=s2.length();
s1=s1+s2;
s2=s1.substring(0,n);

s1=s1.substring(n,n+m);

System.out.println("s1="+s1+"\n s2="+s2);

}
catch(IOException x)
{
System.out.println(x);
}
}
public static void main(String arg[])
{
Swap_2_Strings s=new Swap_2_Strings();
}
}

Is This Answer Correct ?    7 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is difference between object oriented programming structure and object oriented programming system?

1445


if 3 duplicate records, by keeping one original and one duplicate record, and how to delete remaining 2 duplicates in sql server 2008

1595


Explain three modes in which files can be accessed from python program

1323


What do you understand by modular programming?

670


what is the system development cycle

1261






< DL Compact > tag is used for

1547


how to display xisheet in list box in c# .net

1626


Tips for blog integration by www.esteemwebsolutions.com. Can Any body suggest me to how to make wonderful questions on web integration..

1648


What is Negative testing?

1499


THERE ARE 4 SOURCE FILES WHICH CONTAINS SAME METADATA CREATE A TARGET THAT SHOULD DISPLAY THE FILE NAME ALONG WITH THE RECORD PLEASE SEND THE ANSWERFOR THIS QUESTION WITH MAPPING

1681


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

1546


Hello Experts, What is the difference between move and move corresponding exactly? please post me asap

1331


Explain the types of operations? Draw the figure for shift and rotate operations?

2805


What is %Type,%Rowtype?

1840


what is the difference between an OS(operating system) and Framework?

1520