题解 | #合法IP#
合法IP
https://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] ip = in.nextLine().split("\\.");
int legalCount = 0;
for (int i = 0; i < ip.length; i++) {
if (ip[i].matches("[1-9]\\d*|0") && Integer.parseInt(ip[i]) < 1 << 8) {
legalCount++;
}
}
if (legalCount == 4) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
#华为笔试#
