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


Please Help Members By Posting Answers For Below Questions

Enlist diffrent types of inheritance supported by java?

682


What is serial version uid and its importance in java?

796


What is class and its types?

751


Why is java called java?

778


Why is singleton class used?

761


What is the same as procedures?

742


Why Java doesn’t support multiple inheritance?

809


Explain restrictions for using anonymous inner classes?

818


Is break statement can be used as labels in java?

698


Explain about version control?

762


What is variable length arguments in java?

713


What is jrmp?

727


What is difference between add() and addelement() in vector?

1287


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.

1769


What is the difference between static and non-static variables in java programming?

697