Java program to check a given IP address is valid or not
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
In this program, we will check a given IP address is valid or not using the matches() method by applying regular expression.
Program/Source Code:
The source code to check a given IP address is valid or not is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a public class Main. It contain two static methods validate() and main().
The validate() method returns true when the given string contains a valid IP address otherwise it returns false.
The main() method is an entry point for the program. Here, we used the regular expression in matches() method to check a given IP address is valid or not and printed the appropriate message.