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 |
I have 100 records in a table with two rows. I need to display 10 records per page like Google Search. I need only the Logic(Pagination) in Pure Java. No JSP and all..Thanks in Advance...
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? Or extending thread class or implementing runnable interface. Which is better? : Java thread
How many bytes is a string?
What is static binding and where it occurs?
Explain all java features with real time examples
How to print nodes of a Binary tree?
How do you write a scanner class in java?
What does function identity () do?
What is the role of the java.rmi.naming class?
ublic class Java_Coding_Samples { public static void JavaHungr(NumberFormatException ae){ System.out.println("integer"); } public static void JavaHungry(Exception e){ System.out.println("string"); } public static void JavaHungry(ArithmeticException ae){ System.out.println("object"); } public static void main(String[] args) { JavaHungry(null); }
What are the types of relation?
what is custom tags with example?