forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefanged_IPv4.java
More file actions
35 lines (31 loc) · 833 Bytes
/
Defanged_IPv4.java
File metadata and controls
35 lines (31 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.*;
class Main {
public static void main(String args[]) {
int c = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter IPv4 address");
String s = sc.next();
for (int i = 0; i < s.length(); i++)
if (s.charAt(i) == '.')
c++;
s = s.replace(".", "[.]");
if (c == 3)
System.out.println("Defanged IPv4 address : " + s);
else
System.out.println("Not a valid IPv4 address");
}
}
/*
Sample Input and Output :
Enter IPv4 address
1.1.1.1
Defanged IPv4 address : 1[.]1[.]1[.]1
Enter IPv4 address
2500.100.50.0
Defanged IPv4 address : 2500[.]100[.]50[.]0
Enter IPv4 address
1.1.1.1.
Not a valid IPv4 address
Time Complexity: O(n) where n is the length of address
Space Complexity: O(1)
*/