stopping a loop in java
<pre><code>for (int n1 = in.nextInt(); n1 &gt;= 0; n1 = in.nextInt())
  {
          int total = 0;
          int count = 0;

          while (n1 &gt;= 0)
          {
                  n1 = in.nextInt();
                  total = total + n1;
                  count = count + 1;

          }
          out.println(total);
          out.println(count);
  } 
</code></pre>

<p>i want all the numbers that I enter to be added up, is this code correct? It only adds my last 2 inputs. I want the loop keep going until the user enters a negative number, then then loop stops and then it outputs my total and count. </p>

<pre><code>Scanner in = new Scanner(System.in);
Printstream out = System.out;
</code></pre>
