Project Euler problems 18/67: maximum path sum I recently solved problems 18/67 in Project Euler. My code is long and I think it could be more effective. I solved the problem with dynamic programming and am new to it, so I want to improve my dynamic programming.  I think my running time is acceptable: 0.214 seconds.

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

public class EighteenNSixtyseven {
@SuppressWarnings("rawtypes")
public ArrayList&lt;ArrayList&gt; readFile() {
    ArrayList&lt;ArrayList&gt; nodeList = new ArrayList&lt;ArrayList&gt;();
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader("Triangle.txt"));
        String tmp = reader.readLine();
        while (tmp != null) {
            String[] nums = tmp.split("\\s+");
            ArrayList&lt;Integer&gt; nmb = new ArrayList&lt;Integer&gt;();
            for (int i = 0; i &lt; nums.length; i++) {
                nmb.add(Integer.parseInt(nums[i]));
            }
            nodeList.add(nmb);
                                     // im adding an ArrayList to the ArrayList
            tmp = reader.readLine();    // where the first ArrayList index is the 
        }                                // the specific row and the other ArrayList
                                        // containing the numbers
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return nodeList;
}
public static void main(String[] args) {
    EighteenNSixtyseven ad = new EighteenNSixtyseven();
    long start = System.currentTimeMillis();  // starting time
    @SuppressWarnings("rawtypes")               // eclipse suggested this??? Why?
    ArrayList&lt;ArrayList&gt; list = ad.readFile(); // reading the file with numbers in triangle
    int size = list.size() - 1;
    int calc = 0;
    int otherCalc = 0;
    int q = 0;
    ArrayList&lt;Integer&gt; temp1 = new ArrayList&lt;Integer&gt;();
    ArrayList&lt;Integer&gt; temp2 = new ArrayList&lt;Integer&gt;();
    while (size &gt;= 1) {
        temp1 = list.get(size);
        temp2 = list.get(size - 1);
        q = 0;
        if (temp2.size() != 1) {
            while (q &lt; temp2.size() - 1) {
                for (int k = 0; k &lt; temp2.size(); k++) {    // checking which    
                    calc = temp1.get(q) + temp2.get(k);        // sum gives the bigger on
                    otherCalc = temp1.get(q + 1) + temp2.get(k); // adding numbers
                    if (calc &gt; otherCalc) {                        // in the lower line
                        temp2.set(k, calc);                    // with the ones in the line
                    } else {                                // over to the right and left
                        temp2.set(k, otherCalc);
                    }
                    q++;
                }
                size--;
            }
        } else {
            calc = temp1.get(0) + temp2.get(0);            // had to add this or the
            otherCalc = temp1.get(1) + temp2.get(0);    // array is outOufBounds
            if (calc &gt; otherCalc) {
                temp2.set(0, calc);
                size--;
            } else {
                temp2.set(0, otherCalc);
                size--;
            }
        }
    }

    System.out.println("\nThe sum total is = " + temp2.get(0));
    long elapsedTimeMillis = System.currentTimeMillis() - start;
    float elapsedTimeSec = elapsedTimeMillis / 1000F;
    System.out.println("Tid " + elapsedTimeSec);
}
}


As you can see, the code is a bit messy! Any suggestions will be highly appreciated!
Even before starting the review I have to disappoint you. The problem has nothing to do with the dynamic programming. Now let's go.


Naming: Avoid meaningless names, such as q, temp1, temp2, calc and otherCalc.
Responsibilities: You correctly separated IO in a method of its own. The actual calculations also deserve to be separated.
Algorithm: A triple nesting loop is an immediate red flag. In fact, you don't need to iterate over q (which is the index into the bottom row, right? - it took me a while to figure it out) at all: the kth element of the upper row can be only influenced by kth and k+1th of the bottom one. Taking it into consideration, you'd eliminate one level of nesting as well as a really ugly special case of temp2.size() == 1. 


The core loop should look like

    for (k = 0; k &lt; upperRow.size(); k++)
            upperRow[k] += max(bottomRow[k], bottomRow[k+1]);


That said, let me reiterate a very important rule of no raw loops: for every loop you write, think of it as a standalone method and figure out a meaningful name for it. If you can't than you effectively don't know what it is doing!