title: Car fueling problem in java. Can anyone figure out any error in while loop condition?
body: <pre><code>import java.util.*;
  import java.io.*;
  
  public class CarFueling {
   static int compute_refills(int dist,int tank,int stops[],int n){
      
          int current_refills=0;
          int num_refills=0;
          int last_refill=0;
          while(current_refills&lt;=n) {
               last_refill = current_refills;
              while ((current_refills &lt;= n) &amp;&amp; (stops[current_refills + 1] - stops[last_refill]) &lt;= tank) {
                  current_refills = current_refills + 1;
              }
  
              if (current_refills == last_refill)
                  return -1;
              if (current_refills &lt;= n)
                  num_refills = num_refills + 1;
  
  
          }
          return num_refills;
      }
  
      public static void main(String[] args) {
          Scanner scanner = new Scanner(System.in);
          int dist = scanner.nextInt();
          int tank = scanner.nextInt();
         int n = scanner.nextInt();
          int stops[] = new int[n*n*n];// to solve array index out of bound exception increase the size of the array
          for (int i = 0; i &lt; n; i++) {
              stops[i] = scanner.nextInt();
          }
  
         System.out.println(compute_refills(dist,tank,stops,n));
  
      }
  }
  </code></pre>
  <p>I think there is some issue in my while loop condition.<br />
  Input:<br />
  950
  400<br />
  4<br />
  200 375 550 750<br />
  my output:<br />
  1<br />
  correct output:<br />
  2</p>