title: Sum of elements in an array
body: <p>I'm working on a simple assignment for a summer java course and was just hoping you guys could take a look at my code and see if the way I did it is the best way. The purpose is to create a simple <code>int</code> array with at least 25 elements and use a loop to traverse it and add up all the elements.  I had some issues but looks like I got it to work. After I work it out I did a little research and saw some similar stuff where people were using a For Each loop (enhanced loop).  Would that be a better option? I'm kinda confused on the best ways to use that opposed to a regular for loop.  </p>
  
  <p>Anyway, any comments or criticism in helping me be a better programmer!</p>
  
  <pre><code>public class Traversals {
  
      public static void main(String[] args) {
  
          int absenceTotal = 0;
          // initialize array with 30 days of absences.
          int absencesArr[] = { 1, 3, 0, 9, 8, 23, 1, 
                  11, 23, 5, 6, 7, 10, 1, 5,
                  14, 2, 4, 0, 0, 1, 3, 2, 1, 
                  1, 0, 0, 1, 3, 7, 2 };
  
          for (int i = 0; i &lt; absencesArr.length; i++) {
              absencesArr[i] += absenceTotal;
              absenceTotal = absencesArr[i];
          }
          System.out.println("There were " + absenceTotal + " absences that day.");
      }
  }
  </code></pre>