class msc{public static void main(String args[])
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s1,s2;
StringBuffer str=new StringBuffer("");
StringBuffer str2=new StringBuffer("");
StringBuffer str3=new StringBuffer("");
StringBuffer str4=new StringBuffer("");
int i,l1=0,l2=0;
int l3,j,l4;
int count=0,c=0,k=0;
char temp;
System.out.println("Enter first string : ");
s1=br.readLine();
System.out.println("Enter second string : ");
s2=br.readLine();
str=new StringBuffer(s1);
str2=new StringBuffer(s2);
l1=str.length();
l2=str2.length();
l3=l1+l2;
str3.setLength(l3);
System.out.println(l1);
System.out.println(l2);
for(i=0;i
str3.setCharAt(i,str.charAt(i));
}
for(i=0;i
str3.setCharAt(i+l1,str2.charAt(i));
}
System.out.println("The merged string is : "+str3);
for(i=0;i
for(j=i+1;j
if((int)str3.charAt(i)>(int)str3.charAt(j))
{
char b=str3.charAt(i);
str3.setCharAt(i,str3.charAt(j));
str3.setCharAt(j,b);
}}}
System.out.println("The sorted string is : "+str3);
l4=l3*2;
str4.setLength(l4);
for(i=0;i
for(j=i+1;j
if((int)str3.charAt(i)==(int)str3.charAt(j))
{count=count+1;}
}
str4.setCharAt(k,str3.charAt(i));
c=count+1;
k=k+1;
temp=(char)(c+48);
str4.setCharAt(k,temp);
k=k+1;
count=0;
}
System.out.println("The compressed string is : "+str4);
}
catch(Exception e){}
}}
Sample Output :
The merged string is : kapilvaishali
The sorted string is : aaahiiikllpsv
The compressed string is : a3h1i3k1l2p1s1v1
No comments:
Post a Comment