Мне кажется всё правильно, но не пропускает первое условие, подскажите ошибку пожалуйста. Ответ верный выходит, если запустить без проверки
package com.javarush.task.task21.task2101;
/*
Определяем адрес сети
*/
public class Solution {
public static void main(String[] args) {
byte[] ip = new byte[]{(byte) 192, (byte) 168, 1, 2};
byte[] mask = new byte[]{(byte) 255, (byte) 255, (byte) 254, 0};
byte[] netAddress = getNetAddress(ip, mask);
print(ip); //11000000 10101000 00000001 00000010
print(mask); //11111111 11111111 11111110 00000000
print(netAddress); //11000000 10101000 00000000 00000000
}
public static byte[] getNetAddress(byte[] ip, byte[] mask) {
byte[] now = new byte[ip.length];
int i = 0;
int x = 0;
for (byte b : ip) {
String binStr = Integer.toBinaryString(b & 0xFF);
String maskStr = Integer.toBinaryString(b & 0xFF);
now[i] = (byte) ((byte) Integer.parseInt(binStr, 2) & (byte) Integer.parseInt(maskStr, 2));
i++;
}
return now;
}
public static void print(byte[] bytes) {
for (byte b : bytes) {
String binStr = Integer.toBinaryString(b & 0xFF);
System.out.print(("00000000" + binStr + " ").substring(binStr.length()));
}
System.out.println();
}
}