- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem468.java
More file actions
Latest commit
21 lines (17 loc) · 645 Bytes
/
Copy pathProblem468.java
File metadata and controls
21 lines (17 loc) · 645 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
importjava.util.regex.Pattern;
classProblem468 {
publicstaticvoidmain(String[] args) {
StringIP = "1.2.2.3";
System.out.println(newProblem468().validIPAddress(IP));
}
StringchunkIPv4 = "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
PatternpattenIPv4 =
Pattern.compile("^(" + chunkIPv4 + "\\.){3}" + chunkIPv4 + "$");
StringchunkIPv6 = "([0-9a-fA-F]{1,4})";
PatternpattenIPv6 =
Pattern.compile("^(" + chunkIPv6 + "\\:){7}" + chunkIPv6 + "$");
publicStringvalidIPAddress(StringIP) {
if (pattenIPv4.matcher(IP).matches()) return"IPv4";
return (pattenIPv6.matcher(IP).matches()) ? "IPv6" : "Neither";
}
}