count number of matches in two strings java

Solutions on MaxInterview for count number of matches in two strings java by the best coders in the world

showing results for - "count number of matches in two strings java"
Federica
18 May 2019
1for(int i = 0; i < string1.length(); i++) // run loop for length of string1
2        { 
3            ch1 = string1.charAt(i);//first character of string1 
4                       
5            for(int u = 0; u < string2.length(); u++)//compare first char of string1, against each in string2 
6            {  										
7                ch2 = string2.charAt(u); //first character of string2
8                if(ch1 == ch2)
9                { 
10                    matches++; //increment matches found 
11                }
12            }
13                   
14        }
15        
16        System.out.println("Number of matches: " +matches);