class Solution {
public boolean isIPv4(String ip) {
String[] parts = ip.split("\\.");
if (ip.charAt(ip.length()-1) == '.') return false;
if (parts.length != 4) return false;
for (String part: parts) {
System.out.println(part);
if (part.length() == 0) return false;
if (part.charAt(0) == '0' && part.length() > 1) return false;
if (part.length() > 3) return false;
for (int j = 0; j < part.length(); j++) {
if (part.charAt(j) == ':') return false;
if (Character.isLetter(part.charAt(j))) return false;
}
if (Integer.parseInt(part) > 255) return false;
}
return true;
}
public boolean isIPv6(String ip) {
String[] parts = ip.split(":");
if (ip.charAt(ip.length()-1) == ':') return false;
if (parts.length != 8) return false;
for (String part: parts) {
if (part.length() == 0) return false;
if (part.length() > 4) return false;
for (int j = 0; j < part.length(); j++) {
if (Character.isDigit(part.charAt(j))) continue;
if (part.charAt(j) == '.') return false;
if ("abcdefABCDEF".contains(String.valueOf(part.charAt(j))) == false) return false;
}
}
return true;
}
public String validIPAddress(String queryIP) {
if (queryIP.length() == 0) return "Neither";
if (isIPv4(queryIP)) return "IPv4";
if (isIPv6(queryIP)) return "IPv6";
return "Neither";
}
}