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
Enlist diffrent types of inheritance supported by java?
What is serial version uid and its importance in java?
What is class and its types?
Why is java called java?
Why is singleton class used?
What is the same as procedures?
Why Java doesn’t support multiple inheritance?
Explain restrictions for using anonymous inner classes?
Is break statement can be used as labels in java?
Explain about version control?
What is variable length arguments in java?
What is jrmp?
What is difference between add() and addelement() in vector?
there are N number of matchboxes numbered 1...N.each matchbox contain various number of stick.Two player can alternatevely pick some amount of stick from the higest stick containing box . The player is condidered win if there is no stick after his move.Find the final move so that the move player win. Note:In case the number of stick is equal ,pick the stick from the higest numbered box.
What is the difference between static and non-static variables in java programming?