program to validate the IP address? Validity range should be
0 to 255
Answer / 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 |
Can we have 2 main methods in java class?
What is the meaning of immutable regarding string?
Can an exception be rethrown?
What are the advantages of exception handling in java?
Can a serialized object be transferred via network?
Name two subclasses of the TextComponent class?
What is mnemonic code?
What is the difference between declaration and definition in java?
Explain about the performance aspects of core java?
What will happen if we write code like: try{}catch(exception e)catch(IOException i)
What is the functionality of Webserver?
What is the purpose of garbage collection in java, and when is it used?