-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipclasss.java
More file actions
58 lines (58 loc) · 1.55 KB
/
Copy pathipclasss.java
File metadata and controls
58 lines (58 loc) · 1.55 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.lang.*;
import java.io.*;
class ipclasss
{
public static void main(String args[])throws Exception
{
int ip[]=new int[4];
int i=0,j=0,k=0,remainder;
String bin;
while(j!=3)
{
while(i<args[0].length() && args[0].charAt(i++) =='.')
{
ip[j++]=Integer.parseInt(args[0].substring(k,i-1));
k=i;
}
}
ip[j++]=Integer.parseInt(args[0].substring(k,args[0].length()));
if(ip[0] >-1 &&ip[0] < 256 && ip[1] > -1 && ip[1] < 256 && ip[2] > -1 && ip[2] < 256 && ip[3] > -1 && ip[3] < 256)
{
System.out.println("Ip is valid");
bin=Integer.toBinaryString(ip[0]);
if(bin.charAt(0)=='0')
{
System.out.println("The Ip entered is a Class A Address");
System.out.println("Net ID :- "+ip[0]);
System.out.println("Host ID :- "+ip[1]+"."+ip[2]+"."+ip[3]);
}
else
{
if(bin.charAt(1)=='0')
{
System.out.println("The Ip entered is a Class B Address");
System.out.println("Net ID :- "+ip[0]+"."+ip[1]);
System.out.println("Host ID :- "+ip[2]+"."+ip[3]);
}
else
{
if(bin.charAt(2)=='0')
{
System.out.println("The Ip entered is a Class C Address");
System.out.println("Net ID :- "+ip[0]+"."+ip[1]+"."+ip[2]);
System.out.println("Host ID :- "+ip[3]);
}
else
{
if(bin.charAt(3)=='0')
System.out.println("The Ip entered is a Class D Address");
else
System.out.println("The Ip entered is a Class E Address");
}
}
}
}
else
System.out.println("Ip is invalid");
}
}