Common Characters In Two Strings
Common Characters In Two Strings import java.util.*;
class Common
{
public static void main(String args[])
{
Scanner src= new Scanner(System.in);
System.out.println("enter the two strings");
String s1=src.nextLine();
String s2=src.nextLine();
String c="";
StringBuffer sb=new StringBuffer(c);
for(int i=0;i<s2.length();i++)
{
char ch=s2.charAt(i);
for(int j=0;j<s1.length();j++)
{
if(ch==s1.charAt(j))
{
int k;
for( k=0;k<sb.length();k++)
{
if(ch==sb.charAt(k))
break;
else
continue;
}
if(k>=sb.length())
sb.append(ch);
}
else
continue;
}
}
System.out.println(sb);
}
}
0 comments :