Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. package correcteur;
  2.  
  3. import java.util.*;
  4.  
  5. /**
  6. * Classe DistanceHamming : classe qui représente la distance de Hamming,
  7. * pour calculer la distance entre deux mots.
  8. *
  9. * @author Solen Quiniou & Arnaud Lanoix
  10. * @version 2018-10-08
  11. *
  12. */
  13. public class DistanceHamming implements Distance {
  14.  
  15.  
  16. @Override
  17. public int calcule(String mot1, String mot2) {
  18.  
  19. int compt = 0;
  20. int tailleMin = Math.min(mot1.length(), mot2.length());
  21. int tailleMax = Math.max(mot1.length(), mot2.length());
  22.  
  23. for (int i = 0; i < tailleMin; i++)
  24. {
  25. if (mot1.charAt(i) != mot2.charAt(i)) {
  26. compt++;
  27. }
  28.  
  29. }
  30. compt = compt + (tailleMax-tailleMin);
  31. return compt;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement