Write a recursive function named canmakesum that takes a list of * integers and an integer target value (sum) and returns true if it is * possible to have some set of values from the list that sum to the * target value.

Respuesta :

// Java program to find sum of array

// elements using recursion.

class Test {

   static int arr[] = { 1, 2, 3, 4, 5 };

   // Return sum of elements in A[0..N-1]

   // using recursion.

   static int findSum(int A[], int N)

   {

       if (N <= 0)

           return 0;

       return (findSum(A, N - 1) + A[N - 1]);

   }

   // Driver method

   public static void main(String[] args)

   {

       System.out.println(findSum(arr, arr.length));

   }

}