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
How do you print array in java?
What is an immutable class?
Which is the best sorting technique in java?
Which collection is ordered in java?
What is off heap memory?
What is the driver class?
When should I use a singleton?
What is set and get methods in java?
What are void methods?
Give us a program to check for parenthesis matching using stack.
Explain about the select method with an example?
How do you get the length of a string in java?
Is java an ide?
what r advatages of websphere? & how to deploy?
How do you create a method in java?