title: How to identify the number of common character between two strings?
body: <blockquote>
  <p>Given 2 strings, str1 and str2, as input, return the count of the chars which are in the same position in str1 and str2.</p>
  </blockquote>
  <h1>Sample Input #1</h1>
  <p>count(&quot;New York&quot;,&quot;New Delhi&quot;)</p>
  <h1>Sample Output #1</h1>
  <p>4</p>
  <p>Because the two strings share the same four leading characters: &quot;New &quot;</p>
  <h1>Sample Input #2</h1>
  <p>count(&quot;rhinoceroses&quot;,&quot;hippopotamus&quot;)</p>
  <h1>Sample Output #2</h1>
  <p>2</p>
  <p>Because 'o' occupies the fourth position and 's' the eleventh position in both strings.</p>
  <p><strong>MyApproach</strong></p>
  <p>@Edit</p>
  <pre><code>public int count(String str1, String str2)
  {
      int p=0;
      int k=0;
      int count=0;
      int l1=str1.length();
      int l2=str2.length();
      if(l1&gt;=l2)
      {
       while(k&lt;l2)
       {
           char ch1=str1.charAt(p);
           char ch2=str2.charAt(k);
      
              if(ch1==ch2)
              {
                  p++;
                  k++;
                  count++;
              }
              else
              {
                  p++;
                  k++;
                  
              }
        }         
       }
       else
       {
           char ch1=str1.charAt(p);
           char ch2=str2.charAt(k);
      
           while(k&lt;l1)
           {
               
              if(ch1==ch2)
              {
                  p++;
                  k++;
                  count++;
              }
              else
              {
                  p++;
                  k++;
                  
              }
            }         
        }
     return count;
  }   
  </code></pre>
  <p>Parameters            Actual Output Expected Output</p>
  <p>'Trisect''Classes'    0             1</p>
  <blockquote>
  <p>I am getting correct output now.</p>
  </blockquote>
  <p>Thanku</p>