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
Need provab technical test questions
hi this is uday i want prepare for nic exam if any one have previous question papers please send me or atlest guide me how to prepare my ID is udaykiran4u@in.com
Any real time example of O2C process from taking order till creating invoice.
what are resources in case of Threads
what is the system development cycle
What r the attributes using in Win Runner?
suppose we have ten members of a physical file but we want the output of last 5 members only.how to achieve that?
Write code to read the records from a file and load any array of size 99?make sure that you take care of all the error conditions?
Write a shell program. Enter number of days from keyboard. Find out the number of years, month and days it contains
what is meant by life cycle of a business
Can anyone send me NIC question papers alongwith answers on nidhi1485@yahoo.co.in? Urgently needed.. Thanks in advance
how to check single or double byte in struts
what are the topics choosen for jam round for interviews
what is difference between object oriented programming structure and object oriented programming system?
how do u handle table control inbdc explain the process in steps iwant the answer in urgent please forward this even i know how to explain there