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 will you prove that java swing is multithreaded?
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??/
What for decision coverage and modified condition decision coverage are used? Wat is the difference between them?
what is an INI file?
iam confused among testing ,.net and java. can anybody help me.
iam confused to choose among testing, .net and java can anybody help me????????
I'm new to ABAP. What is Module pool in SAP?
how do i create my own exception class which will restrict IO exception?
how to generate dsnless connectivity in j2ee
can we allocate memory for interface? if no then why?
Always use scope terminator like End-If with IF, End- Evaluate with Evaluate statement.Can somebody explain me the detail logical explanation?
What is the difference between WebIntelligence and Designer in creating universes?
shall we execute our java programmes in jre
What is dialog programming?
what are the topics choosen for jam round for interviews