Java Program to find common chrectures in three Strings

Input: consider 3 strings are “AMITABH”, “BACHCHAN”, “RAJNIKANTH”

program :

class FindCommonAlphabets
{
      public static String find(String str1,String str2)
        {
              int i,j,k,flag;
              String result=””;
              char s1[]=str1.toCharArray();
              char s2[]=str2.toCharArray();
       
    for(i=0;i<s1.length;i++)
                   {
                     for(j=0;j<s2.length;j++)
                        {
                       flag=1;
                              if(s1[i]==s2[j])
                                    {      char temp[]=result.toCharArray();
                    for(k=0;k<temp.length;k++)
                      if(temp[k]==s2[j])
                                  {  flag=0; }
                    if(flag==1)
                    { result=result+s1[i]; }
                                }
                        }
                }
              return result;                 
        }
    public static void main(String args[])
    {
        System.out.println(FindCommonAlphabets.find(“AMITABH”,FindCommonAlphabets.find(“BACHCHAN”,”RAJNIKANTH”)));
    }
}
O/P :   A H
  

Leave a Reply

Your email address will not be published. Required fields are marked *

Enable Notifications OK No thanks