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 |
What is the difference between static and global variables and also define what are volatile variables?
0 Answers Flextronics, Hexaware,
Why is it called boolean?
What is data type modifier?
What is the use of arrays tostring () in java?
Does constructor creates the object ?
Can we have more than one package statement in the source file?
What is an object in java and how is it created?
How many types of flags are there?
class{ ... ... interface myinterface{ ... ... } abstract class{ .. .. } ... .. .. } is this possible to write "Interface and/ or Abstract class inside a class ? if possible whcich one is possible is only interface? is only abstract?
What are anonymous inner classes?
How many types of the indexof method are there for strings?
What is a subsequence of a string?