Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


program to validate the IP address? Validity range should be
0 to 255



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

Post New Answer

More Core Java Interview Questions

what is difference between abstract and interface? can i give real time example for the two topics?

7 Answers  


Is string is a keyword in java?

0 Answers  


Explain enumeration in java?

0 Answers  


Are maps ordered java?

0 Answers  


Explain different ways of creating a thread?

0 Answers  


What Method and class used for Connection pooling ?

5 Answers   TCS, Wipro,


Write a code to create a trigger to call a stored procedure

0 Answers  


Why we use multi threading instead of multiprocessing?

0 Answers  


What's the purpose of static methods and static variables?

0 Answers  


What exactly is methodology?

0 Answers  


Can you instantiate the math class in Java?

0 Answers   IBS,


Why scanner is used in java?

0 Answers  


Categories