Hi all, i am new to java and also this forums,could any one help me solve my doubts, i am trying to learn java programming through examples.
Task: Develop a program that parses an ip address and subnet mask and prints out the associated network id and host id.
Doubt 1: Please tell me algorithm for this, i am lot of confused.
Doubt 2: How can i store an Ip address in a variable.? what datatype i should use. I am not sure if i enter a string would it be recognized as an ip address or just as a series of charecters...
May be i am wrong. can any one shed some light on my head.
Joined: Jul 11, 2008
You can store your ip address in a string but yes please see that what is the required output data type because after you pic the values from array .
Can you use split function .You can easily split using split() function in java (don't forget to convert your ip address to string first ) .Then you will get an array in return of which values can be easily identified.
Also if split is not an option then you can manually write the code to split a string .
If this doesn't clears your doubt please enter the input and output values here.
SCJP 1.5,SCWCD 1.5
Joined: Oct 13, 2005
Welcome to the Ranch
IPs have a set format which you should be able to identify easily with a regular expression.
Joined: Mar 22, 2005
Since you seem unsure of how, exactly, an IP address looks like, I'd start by reading up on IP version 4 addresses at http://en.wikipedia.org/wiki/IP_address. Once you've got that mastered, you can move on to include IP version 6 addresses.