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!

 

 

  • 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.