Answers for "count number of matches in two strings java"

0

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);
Posted by: Guest on June-10-2020

Code answers related to "count number of matches in two strings java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language