Ok, so far my program allows user input, recognizes how many numbers are stored in the array list and then outputs those numbers that are stored. How can I sum all the numbers entered by the user?
import java.util.Scanner;
import java.util.ArrayList;
public class lab5
{
public static void main (String[]args)
{
Scanner userInput = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<>();
//Creates initial value for nextInt variable
int nextInt = -1;
//Create loop to store user input into array list until 0 is entered
while((nextInt = userInput.nextInt()) != 0)
{
list.add(nextInt);
}
//Calculate average once zero is inputted
if (nextInt == 0)
{
System.out.println("There are " + list.size() + " numbers in this array list");
System.out.println("The numbers are " + list);
System.out.println("The sum of the number are ")
}
}
}