take input until input positive number : <p>Take two integers p &amp; q ... Sum should be printed of p to next q numbers including p .. if q &lt;= 0 , then it will take the value of q again ...</p>

<p>Input :::: 3 2
Output :::: 7 (p=3 &amp; q = 2 ..... So from 3 to next 2 numbers are 3 &amp; 4 as it will be included in the sum ... Now we will have to print the sum of 3+4 and that's 7 )</p>

<p>Input ::: 4 -1 1
Output :::. 4 ( as the next number is 4 )</p>

<p>That means we have to start counting from the taken integer ....</p>

<p>Solve it and drop the solution here ......</p>

<pre><code>import java.util.Scanner;
public class Ahmed {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int p=sc.nextInt();
      int q=sc.nextInt();
      int sum=0;
      if(q&gt;=0){
      for(int i=1; i&lt;=q ;i++) {
        sum=p+sum;
        p++;
       }
      }
      else{
        q=sc.nextInt();
        for(int i=1; i&lt;=q ;i++) {
        sum=p+sum;
        p++;
       }
      }
      System.out.println(sum);
    }
}
</code></pre>

<p>if I take input 4 -1 -1 there is a error. Loop will continue until I take q input a positive number or 0;</p>

<p>Correct input 4 -1 -1 2 output 9. </p>
