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 is the difference between keyword and identifier?
How do you do exponents in java?
Can we override constructor?
Can classes declared using the abstract keyword cab be instantiated?
What is the implementation of destroy method in java. Is it native or java code?
What is difference between class and object in java?
What is numel matlab?
How to sort elements in a parallel array in java?
What is method in java ?
Why can we not override static method?
What is the difference between yielding and sleeping in java programming?
Can a java program have 2 main methods?
Explain the term virtual machine?
What is a constructor overloading in java?
What is collections framework?