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 difference between == and === in js?
What is the purpose of the strictfp keyword?
When is the finalize() called? What is the purpose of finalization?
how to convert Java project into Maven ?
What does super keyword do?
What is a boolean expression in java?
Where are local variables stored?
What exactly is methodology?
How is final different from finally and finalize?
What is the functionability stubs and skeletons?
What do you mean Abstraction in java?
Addition to previous section relative word 5th one was Putrid ans: rotten, also there was prob. in 1st section on bucket weight ans:10kg, also there was a prob. on train speed to find bridge length ans:800 mtrs.
What about interthread communication and how it takes place in java?
what is the swingutilities.invokelater(runnable) method for? : Java thread
Explain the JDB in depth & command line.