ktsirig Posted April 28, 2009 Share Posted April 28, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/156031-creating-and-working-with-dynamic-arrays/ Share on other sites More sharing options...
Zhadus Posted May 7, 2009 Share Posted May 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/156031-creating-and-working-with-dynamic-arrays/#findComment-828565 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.