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 |
heavy components means what?
What are the parts of methodology?
Can we write method inside a method in java?
There is a Banking application. It has 2 types of account, Savings and Current. Write a method calculateInterest by passing an ArrayList of these account objects and calculate Interest accordingly. Write code for this situation
What are the wrapped, classes?
Default layout of panel and frame?
Is java 1.7 the same as java 7?
How do you declare an infinite loop?
Which is faster string or stringbuilder?
How to split a string in java?
Can we execute a program without main?
Is set thread safe java?