Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

How will you prove that java swing is multithreaded?

2297


we create a pf with 3 fields.2 is defined as keyfields.we lock it with alcobj command.how we find out whether the file is locked or not?is it dspfd??/

2034


What for decision coverage and modified condition decision coverage are used? Wat is the difference between them?

2152


what is an INI file?

2114


iam confused among testing ,.net and java. can anybody help me.

2012


iam confused to choose among testing, .net and java can anybody help me????????

2089


I'm new to ABAP. What is Module pool in SAP?

2592


how do i create my own exception class which will restrict IO exception?

2743


how to generate dsnless connectivity in j2ee

2026


can we allocate memory for interface? if no then why?

1918


Always use scope terminator like End-If with IF, End- Evaluate with Evaluate statement.Can somebody explain me the detail logical explanation?

1995


What is the difference between WebIntelligence and Designer in creating universes?

2059


shall we execute our java programmes in jre

2280


What is dialog programming?

2045


what are the topics choosen for jam round for interviews

1663