Filling Array with user input and using if statements to do arithmetic depending on the value inside array
<p>Here's the question:</p>

<p>Write a Java program that reads in a series of positive integer and writes out the product of all the integers less than 25 and the sum of all the integers greater than or equal to 25. Use 0 as a sentinel value.</p>

<p>I was able to understand how to let the user add the input to an array. But I could not find a way to integrate the code with if statements to make a full working program to do the task. Here's my findings as of now;</p>

<pre><code>import java.util.*;
public class UserInput {
    public static void main(String[] args) {

        List&lt;String&gt; list = new ArrayList&lt;String&gt;();
        Scanner stdin = new Scanner(System.in);

        do {
            System.out.println("Current list is " + list);
            System.out.println("Add more? (y/n)");
            if (stdin.next().startsWith("y")) {
                System.out.println("Enter : ");
                list.add(stdin.next());
            } else {
                break;
            }
        } while (true);

        System.out.println("List is " + list);
        String[] arr = list.toArray(new String[0]);
        System.out.println("Array is " + Arrays.toString(arr));
    }
}
</code></pre>

<p>How is it possible to make the array read the input and find the product of all numbers under 25 and the sum of all the numbers above 25. Between, what is sentinel value and how useful is it to know?</p>

<p><strong>Solution:</strong>
After hours of tweaking the answers posted by volunteers below, I was able to find a solution which worked for me. I hereby posted it in case anyone finds it useful;</p>

<pre><code>import java.util.*;
  public class UserInput {
  public static void main(String[] args) {

List&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
Scanner stdin = new Scanner(System.in);
do{
    System.out.println("Current list is : " + list);
    System.out.println("Enter number : ");
    int  entered = stdin.nextInt();
    if(entered == 0){
        int sum = 0,product = 1;
        for(Integer number : list){
            if(number&lt;25){
                sum += number; 
            }else if(number &gt;= 25){
                product *= number;
            }
        }
        System.out.println("sum : " + sum);
        System.out.println("product : " + product);
    }else{
        list.add(entered);
        int sum = 0,product = 1;
        for(Integer number : list){
            if(number&lt;25){
                sum += number; 
            }else if(number &gt;= 25){
                product *= number;
            }
        }
        System.out.println("sum : " + sum);
        System.out.println("product : " + product);
    }           
    System.out.println("Add more numbers to the list ? (Y/N) : ");

    } while(stdin.next().equalsIgnoreCase("y"));
}
}
</code></pre>

<p>Thanks to everyone for your posts and comments! It was really helpful! :)</p>
