program to validate the IP address? Validity range should be
0 to 255
Answer Posted / jyoti
import java.util.StringTokenizer;
public class ValidateIP {
String IP = null;
public void validate(String IP)
{
this.IP=IP;
StringTokenizer st=new StringTokenizer
(IP,".");
int i=1;
while(st.hasMoreTokens())
{
int valid=checkRange(st.nextToken
());
if(valid == 0)
{
System.out.println("Token "
+ i + "is not valid");
}
else
{
System.out.println("Token "
+ i + "is valid");
}
i++;
}
}
public int checkRange(String tok)
{
int n=Integer.parseInt(tok);
if(n>=0 && n<=255)
{
return 1;
}
return 0;
}
public static void main(String args[])
{
ValidateIP v=new ValidateIP();
v.validate("192.165.256.1");
}
}
| Is This Answer Correct ? | 23 Yes | 2 No |
Post New Answer View All Answers
What does 0 mean in boolean?
What is a singleton in genetics?
What kind of variables a class can consist of?
What does indexof mean?
whar are the draw backs of programming lang step by step in Clang and next in C++ and next and in Java nad in .Net
You're given a Boolean 2D matrix, can you find the number of islands?
Why do we need hashset in java?
What is a lock or purpose of locks in java?
What are the three types of design patterns?
What is the disadvantage of java?
What is meant by attribute?
How do you create a reference in java?
How do you use compareto method?
Explain access modifiers in java.
Why do we create threads in java?