aspose file tools
The moose likes Beginning Java and the fly likes Ipcalculator Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Ipcalculator Help" Watch "Ipcalculator Help" New topic

Ipcalculator Help

Mezan Shareef
Ranch Hand

Joined: Apr 01, 2010
Posts: 40
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.
adil qureshi
Ranch Hand

Joined: Jul 11, 2008
Posts: 48
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
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 41543
Welcome to the Ranch

IPs have a set format which you should be able to identify easily with a regular expression.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42954
Since you seem unsure of how, exactly, an IP address looks like, I'd start by reading up on IP version 4 addresses at Once you've got that mastered, you can move on to include IP version 6 addresses.
I agree. Here's the link:
subject: Ipcalculator Help