Anonymous user
Most frequent k chars distance: Difference between revisions
→{{header|Java}}
Line 197:
=={{header|Java}}==
{{
Translation of the pseudo-code of the Wikipedia article [[wp:Most frequent k characters]] to [[wp:java]] implementation of three functions given in the definition section are given below with [[wp:JavaDoc]] comments:
Line 280:
public static int getDiff(String str1, String str2, int limit) {
int similarity = 0;
int k = 0;
int pos = str2.indexOf(str1.charAt(i));▼
if
if (pos >= 0) {▼
String digitStr1 =
while ( k < str1.length() && !Character.isLetter(str1.charAt(k))) {
▲ }
digitStr1 += str1.charAt(k);
k++;
return limit-similarity;▼
}
int k2 = pos+1;
String digitStr2 = "";
while (k2 < str2.length() && !Character.isLetter(str2.charAt(k2)) ) {
digitStr2 += str2.charAt(k2);
k2++;
}
similarity += Integer.parseInt(digitStr2)
+ Integer.parseInt(digitStr1);
}
}
}
}
/**
|