Hamming Distance between two strings | Java program to find hamming distance b / w two string ; function to calculate Hamming distance ; Driver code ; function call
class GFG { static int hammingDist ( String str1 , String str2 ) { int i = 0 , count = 0 ; while ( i < str1 . length ( ) ) { if ( str1 . charAt ( i ) != str2 . charAt ( i ) ) count ++ ; i ++ ; } return count ; } public static void main ( String [ ] args ) { String str1 = " geekspractice " ; String str2 = " nerdspractise " ; System . out . println ( hammingDist ( str1 , str2 ) ) ; } }