# Finding Common Alphabet Between Two Names.

We have two names, say “AMITABH BACHCHAN ” and “RAJNIKANTH”. Our work is find common alphabet in these two names. The answer would be ‘AITHN’. i have written my code, if you find your code, more easier than mine, please do write in comment box. So lets go!

If you are looking for the solution in C/C++. Please visit Here .

```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace commonAlpha
{
class Program
{
static void Main(string[] args)
{
char[] name1 = {'A','M','I','T','A','B','H','B','A','C','H','C','H','A','N'};
char[] name2 = { 'R', 'A', 'J', 'N', 'I', 'K', 'A', 'N', 'T', 'H' };
StringBuilder s1 = new StringBuilder();
for (int i = 0; i&lt;name1.Count(); i++)
{
for (int j = 0; j &lt; name2.Count(); j++)
{
//compareing two char from both string
if (name1[i] == name2[j])
{
char temp = name2[j];
if (s1.Length != 0)
{
int flag = 0;
//checking whether its already in s1 or not. If yes, flag will be greater than 0 or if not flag=0
for (int k = 0; k &lt; s1.Length; k++)
{
if (s1[k] == temp)
flag++;
}
//confirm that temp is not in s1
if (flag == 0)
{
s1.Append(temp);
}
}
else
s1.Append(temp);
}
}
}
for (int i = 0; i &lt; s1.Length; i++)
Console.Write(s1[i]);
}
}
}
```

## 13 thoughts on “Finding Common Alphabet Between Two Names.”

1. Saad

this code is in c#??

2. deepeshsingh93

Yes! its in C#. Do you need these codes in c or C++??

• har

yes pls give the codes in php and java

• mnishj

Put the code below in my comment between

And execute.

• Saad

yes in C++

3. mnishj

Executes and works like a charm..

4. mnishj
5. mnishj

Add the PHP tags for the below code..
\$str1=”AMITABH BACHCHAN”;
\$str2=”RAJNIKANTH”;
echo “The common alphabets in the two names are: “;
\$arr1=str_split(\$str1);
\$arr2=str_split(\$str2);
\$result=array_unique(array_intersect(\$arr1, \$arr2));
echo implode(\$result);

6. Ankur

• jatt_bloger

hey u can try this one in java

7. sachin

for java ::

public class checking {

public static void main(String[] s){
checking ck=new checking();
String s1=”AMITABH BACHCHAN”;
String s2=”RAJNIKANTH”;
char[] ch1=s1.toCharArray();
char[] ch2=s2.toCharArray();
StringBuilder sb=new StringBuilder();

for(int i=0; i<ch1.length;i++){
for(int j =0;j<ch2.length;j++){
if(ch1[i]==ch2[j]){
int cflag =0; // here to reset again
char c=ch1[i];
for(int k =0; k<sb.length();k++){
if(c==sb.charAt(k)){
cflag++;
}
}

if(cflag==0)
{
sb.append(c);

}
}
}
}
System.out.println(sb);
}

}

• gnanu

in python??