mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
Format code with prettier (#3375)
This commit is contained in:
@@ -5,12 +5,14 @@ import java.util.List;
|
||||
|
||||
public class HammingDistance {
|
||||
|
||||
|
||||
|
||||
public int getHammingDistanceBetweenBits(String senderBits, String receiverBits) {
|
||||
|
||||
if(senderBits.length() != receiverBits.length()) {
|
||||
throw new IllegalArgumentException("Sender and Receiver bits should be same");
|
||||
public int getHammingDistanceBetweenBits(
|
||||
String senderBits,
|
||||
String receiverBits
|
||||
) {
|
||||
if (senderBits.length() != receiverBits.length()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Sender and Receiver bits should be same"
|
||||
);
|
||||
}
|
||||
|
||||
List<byte[]> byteArray = new ArrayList<>();
|
||||
@@ -18,20 +20,19 @@ public class HammingDistance {
|
||||
byteArray.add(senderBits.getBytes());
|
||||
byteArray.add(receiverBits.getBytes());
|
||||
|
||||
|
||||
byte[] senderData = byteArray.get(0);
|
||||
byte[] receiverData = byteArray.get(1);
|
||||
|
||||
int totalErrorBitCount = 0;
|
||||
|
||||
for(int i = 0; i < senderData.length; i++){
|
||||
totalErrorBitCount += senderData[i] ^ receiverData[i];
|
||||
for (int i = 0; i < senderData.length; i++) {
|
||||
totalErrorBitCount += senderData[i] ^ receiverData[i];
|
||||
}
|
||||
|
||||
if(totalErrorBitCount == 0){
|
||||
if (totalErrorBitCount == 0) {
|
||||
System.out.println("No Error bit in data segments");
|
||||
} else{
|
||||
System.out.println("Total Error bit count "+totalErrorBitCount);
|
||||
} else {
|
||||
System.out.println("Total Error bit count " + totalErrorBitCount);
|
||||
}
|
||||
return totalErrorBitCount;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user