Jump to content

creating and working with dynamic arrays


ktsirig

Recommended Posts

Hello all! I am very new to Java programming and have came up with my first problem:

I have a file which has several lines, similar to:

 


ATOM      1  N   SER P  71     -47.333   0.941   8.834  1.00 52.56           N  
ATOM      2  CA  THR P  71     -45.849   0.731   8.796  1.00 53.56           C  
ATOM      3  C   TRY P  71     -45.191   1.608   7.714  1.00 51.61           C  

 

What I want to do is, while reading the text file, find all lines that begin with ATOM and store the 3 letters (in this example SER, THR, TRY) along with the numbers close to them (in this example -47.333, -45.849 and -45.191 respectively).

Once the array is constructed, we need to find the lowest and the highest value of it and substract them.

Could you point me out to some guidelines please?

 

Thank you in advance!

 

 

Link to comment
Share on other sites

  • 2 weeks later...

Read each line into a buffer string and store that into an array. Then use indexOf() to check for "ATOM" within each string. It will return -1 if it doesn't exist in it.

 

For extracting the values, it looks like everything is formatted properly which will help a ton. Just use substring(start, end) to pull the numeric values you want. They all start and end with the same indexes. Pull those out into separate strings or into a new array, convert to integers, and then use your math skills to get what you're looking for. I hope this helps.

 

If you have questions feel free to ask, but I've given you the functions you should need, you can google them for better explanations and syntax etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.