import java.util.HashSet;
import java.util.Set;
String text1 = "Hello";
String text2 = "Hell64664os";
def jaccardSimilarity(str1,str2) {
Set set1 = new HashSet();
Set set2 = new HashSet();
for (char c : str1.toCharArray()) {
set1.add(c);
}
for (char c : str2.toCharArray()) {
set2.add(c);
}
Set intersection = new HashSet(set1);
intersection.retainAll(set2);
int commonCount = intersection.size();
int totalUniqueCount = set1.size() + set2.size() - commonCount;
return (double) commonCount / totalUniqueCount;
}
double similarityScore = jaccardSimilarity(text1, text2);
String formattedScore = String.format("%.2f", similarityScore);
return "Jaccard 相似分数: " + formattedScore;