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
what is difference between object oriented programming structure and object oriented programming system?
if 3 duplicate records, by keeping one original and one duplicate record, and how to delete remaining 2 duplicates in sql server 2008
Explain three modes in which files can be accessed from python program
What do you understand by modular programming?
what is the system development cycle
< DL Compact > tag is used for
how to display xisheet in list box in c# .net
Tips for blog integration by www.esteemwebsolutions.com. Can Any body suggest me to how to make wonderful questions on web integration..
What is Negative testing?
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
what is d main diff between the java and .net framework
Hello Experts, What is the difference between move and move corresponding exactly? please post me asap
Explain the types of operations? Draw the figure for shift and rotate operations?
What is %Type,%Rowtype?
what is the difference between an OS(operating system) and Framework?