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
How to call a C++ function which is compiled with C++ compiler in C code?
diffrence between oracle apps , .NET , SAP
what are the missinschema properties and should we pass primary key in select command
is it possible to learn sap from book without any tutorial. if yes please mention the beginner,s book of sap and also make your valuable advice for self study of sap .
Write a program to find whether a given number is prime or not.
in IBM PC -AT.WAT AT REFERS TO?
1.how to deploy the Maven application in weblogic server? 2.In Real time projects all classes are singleton or some classes only singleton explain? 3.what are the major uses of the designpatterns? 4.explain restful &Soap based services explain?
Always use scope terminator like End-If with IF, End- Evaluate with Evaluate statement.Can somebody explain me the detail logical explanation?
I am looking for selenium RC online Training in chennai. can any one tell me the best institute
How to create a new dataset only duplicate observations in proc sort procedure?
hai i am mca 2009 fresher.please tell me which certification helps me to get an IT job faster which institute is good in hyderabad.please mail me to prasanna.1856@rediff.com
Why did you ever become involved in QA/testing?
Plz sent me in .net 2.0 interview Question & answers?
Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming
In OB52 , How to define two open posting period, Like only 5 and 8 posting should be open.. should not open 6 and 7..period..