fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes hereint a[]
  13. int[]a = {1,2,3,4,5,6};
  14. int[]prefix = new int[a.length+1];
  15. Arrays.fill(prefix,0);
  16. for(int i = 1;i<=a.length;i++){
  17. prefix[i] = prefix[i-1]+a[i-1];
  18. }
  19. System.out.println(findSumInRange(prefix,2,4));
  20. }
  21. static int findSumInRange(int [] prefix ,int l, int r){
  22.  
  23. return prefix[r]-prefix[l-1];
  24. }
  25. }
Success #stdin #stdout 0.12s 54648KB
stdin
Standard input is empty
stdout
9