-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hamming.java
23 lines (22 loc) · 872 Bytes
/
Hamming.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class Hamming {
int hammingDistance = 0;
public Hamming(String leftStrand, String rightStrand) {
if (leftStrand.length() == 0 && rightStrand.length() != 0) {
throw new IllegalArgumentException("left strand must not be empty.");
}
if (rightStrand.length() == 0 && leftStrand.length() != 0) {
throw new IllegalArgumentException("right strand must not be empty.");
}
if (leftStrand.length() != rightStrand.length()) {
throw new IllegalArgumentException("leftStrand and rightStrand must be of equal length.");
}
for (int i = 0; i < leftStrand.length(); i++) {
if (leftStrand.charAt(i) != rightStrand.charAt(i)) {
hammingDistance++;
}
}
}
public int getHammingDistance() {
return hammingDistance;
}
}