Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package correcteur;
- import java.util.*;
- /**
- * Classe DistanceHamming : classe qui représente la distance de Hamming,
- * pour calculer la distance entre deux mots.
- *
- * @author Solen Quiniou & Arnaud Lanoix
- * @version 2018-10-08
- *
- */
- public class DistanceHamming implements Distance {
- @Override
- public int calcule(String mot1, String mot2) {
- int compt = 0;
- int tailleMin = Math.min(mot1.length(), mot2.length());
- int tailleMax = Math.max(mot1.length(), mot2.length());
- for (int i = 0; i < tailleMin; i++)
- {
- if (mot1.charAt(i) != mot2.charAt(i)) {
- compt++;
- }
- }
- compt = compt + (tailleMax-tailleMin);
- return compt;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement