title: How to find the sum of all the numbers entered before or after finding the Sorted array list?
body: <p>I have written a program in ArrayList to find the sorted array. But I have to find the sum of the numbers entered as well.</p>
  
  <p>I couldn't succeed in getting the results as it is in the array list</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Scanner;
  
  public class project1 {
  
  public static void main(String[] args) {
  
  int add = 0;
      Scanner input = new Scanner(System.in);
      System.out.print("Enter 5 numbers: ");
      ArrayList&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      for (int i = 0; i &lt; 5; i++) list.add(input.nextInt());
  
      System.out.println("add" +add);
      System.out.println("Sorting numbers...");
      sort(list);
      System.out.println("Displaying numbers...");
      System.out.println(list);
  
  }
  
  public static void sort(ArrayList&lt;Integer&gt; list) {
      for (int i = 0; i &lt; list.size() - 1; i++) {
          int currentMin = list.get(i);
          int currentIndex = i;
  
          for (int j = i + 1; j &lt; list.size(); j++) {
              if (currentMin &gt; list.get(j)) {
                  currentMin = list.get(j);
                  currentIndex = j;
              }
          }
  
         if (currentIndex != i) {
              list.set(currentIndex, list.get(i));
              list.set(i, currentMin);
          }
      }
  }
  }
  </code></pre>
  
  <p>I am looking to get the sum of the entered numbers along with sorting. Any help will be very appreciated.</p>