title: Array rotate with juggling algorithm fails
body: <p>This question is from G4G array rotation. I am getting an error in the second loop telling me the array is getting out of scope. But I don't understand why.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class timba {
  
      public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int n, d;
          n = sc.nextInt();
          d = sc.nextInt();
  
          int[] arr = new int[n];
  
          for (int i = 0; i &lt; arr.length; i++) {
              arr[i] = sc.nextInt();
          }
  
          while (d &gt; 0) {
              int t;
              t = arr[0];
              for(int j = 0; j &lt; arr.length; j++) {
                 arr[j] = arr[j+1];
              }
              arr[n-1] = t;
              d--;
          }
  
          for (int i = 0; i &lt; arr.length; i++) {
              System.out.println(arr[i]);
          }
      }
  
  }
  </code></pre>