count the number of pairs in an string code example
Example: count number of matches in two strings java
for(int i = 0; i < string1.length(); i++) // run loop for length of string1
{
ch1 = string1.charAt(i);//first character of string1
for(int u = 0; u < string2.length(); u++)//compare first char of string1, against each in string2
{
ch2 = string2.charAt(u); //first character of string2
if(ch1 == ch2)
{
matches++; //increment matches found
}
}
}
System.out.println("Number of matches: " +matches);