fork download
  1.  
  2. class Ideone
  3. {
  4.  
  5. public static double sum(double [] a, int low, int high) throws Exception{
  6. if(low > high){
  7. }
  8. else if(low == high){
  9. return a[low];
  10. }
  11. return sum(a, low, (low+high)/2) + sum(a, (low+high)/2+1, high);
  12. }
  13.  
  14. public static void main(String[] args) throws Exception {
  15. double[] arr = { 0, 1, 2, 3, 4 };
  16.  
  17. System.out.println(sum(arr, 1, 3)); // 6
  18. }
  19. }
Success #stdin #stdout 0.1s 320256KB
stdin
Standard input is empty
stdout
6.0