import java.util.*;public class Solution {/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可** 验证IP地址* @param IP string字符串 一个IP地址字符串* @return string字符串*/public boolean isIPv4(String IP){//没有'.'if(IP.indexOf('.') == -1) return false;String[] ones = IP.split("\\.");if(ones.length != 4) return false;for(int i = 0; i < ones.length; i++){if(ones[i].length() == 0) return false;if(ones[i].length() < 0 || ones[i].length() > 3 || (ones[i].charAt(0) == '0' && ones[i].length() != 1)) return false; int num = 0;for(int j = 0; j < ones[i].length(); j++){char c = ones[i].charAt(j); if(c < '0' || c > '9') return false;num = num * 10 + (int)(c - '0');if(num < 0 || num > 255) return false; }}return true;}public boolean isIPv6(String IP){if(IP.indexOf(":") == -1) return false;String[] ones = IP.split(":",-1);if(ones.length != 8) return false;for(int i = 0; i < ones.length; i++){if(ones[i].length() == 0 ||ones[i].length() > 4) return false;for(int j = 0; j < ones[i].length(); j++){char c = ones[i].charAt(j);boolean expr = (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f');if(!expr)return false;}}return true; }public String solve (String IP) {// write code hereif(isIPv4(IP)){return "IPv4";}else if(isIPv6(IP)){return "IPv6";}return "Neither";}
}