Я пытаюсь определить расстояние Хемминга между двумя массивами целых.Предварительно: aList! = Null, bList! = Null, aList.length == bList.length;Post: вернуть расстояние Хэмминга между двумя массивами целых.Я не уверен, что я делаю неправильно, я только сейчас начинаю учиться кодировать.Любая помощь приветствуется.Заранее спасибо:)
Вот мой код:
public class test {
public static int hammingDistance(int[] aList, int[] bList) {
// check preconditions
if (aList == null || bList == null || aList.length != bList.length)
throw new IllegalArgumentException("Violation of precondition: " +
"hammingDistance. neither parameter may equal null, arrays" +
" must be equal length.");
//Starting a counter
int counter = 0;
System.out.println("test");
//checking to see if there is a mismatch in the values of the two given arrays
for (int i = 0; i < bList.length; i++) {
if (bList[i] != aList[i]) {
//increasing counter everytime there is a mismatch
counter++;
}
}
return counter;
}
public static void main(String[] args) {
int[] aList = { 1,3,3,4 };
int[] bList = { 1,2,10,4 };
System.out.println(hammingDistance(aList, bList));
}
}
Обновлен код