title: How can I find a range in an array using user input?
body: <pre><code>package assignment;
  
  import java.util.Arrays;
  import java.util.Scanner;
  
  
  public class assignment {
  
  
      public static void main(String[] args) {
          double[] a = new double[] {9.0, 8.0, 7.0, 6.0, 5.0, 4.0};
  
          int index1;
          Scanner user_input = new Scanner(System.in);
          System.out.println("index 1 invoeren");
          index1 = user_input.nextInt();
  
          int index2;
          System.out.println("index 2 invoeren");
          index2 = user_input.nextInt();
  
          //System.out.println(index1);
          //System.out.println(index2);
  
  
      }
  
      public void DoubleSegsum(double[] a, int from, int to){
  
      }
  
  }
  </code></pre>
  
  <p>I need to write a method DoubleSegsum (as seen last) where I can get the sum of the elements of <code>a</code>, between position <code>from</code> and <code>to</code>.
  For example (a, 2, 4) should return 13. 
  I was trying something with </p>
  
  <pre><code>Arrays.asList(a).indexOf(index1)
  </code></pre>
  
  <p>but that will give me <code>-1</code> every time
  And I don't know how to make it wors in the other method</p>