-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHamming.java
More file actions
29 lines (22 loc) · 710 Bytes
/
Copy pathHamming.java
File metadata and controls
29 lines (22 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class Hamming {
public String left = "";
public String right = "";
public Hamming(String leftStrand, String rightStrand) {
if (leftStrand.length() != rightStrand.length()){
throw new IllegalArgumentException("strands must be of equal length");
}
else {
this.left = leftStrand;
this.right = rightStrand;
}
}
public int getHammingDistance() {
int differenceCount = 0;
for (int i = 0; i < this.left.length(); i++){
if (this.left.charAt(i) != this.right.charAt(i)){
differenceCount++;
}
}
return differenceCount;
}
}