forked from RodneyShag/HackerRank_solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
354f4d9
commit 0670409
Showing
2 changed files
with
22 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.Scanner; | ||
|
||
class Solution{ | ||
|
||
public static void main(String []args){ | ||
Scanner in = new Scanner(System.in); | ||
while(in.hasNext()){ | ||
String IP = in.next(); | ||
System.out.println(IP.matches(new MyRegex().pattern)); | ||
} | ||
|
||
} | ||
/* | ||
[01]?\\d{1,2} matches numbers 0-199. | ||
2[0-4]\\d matches numbers 200-249 | ||
25[0-5] matches numbers 250-255 | ||
*/ | ||
class MyRegex { | ||
String num = "([01]?\\d{1,2}|2[0-4]\\d|25[0-5])"; | ||
String pattern = num + "." + num + "." + num + "." + num; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters