Embed presentation
Download to read offline
![Write a method called recAdd that will add the (integer) elements of an array. For example if the
array were {4,8,10} the method would return 22. Note the method will need to take as parameter
the array and also the index of the last element.
public class Lab14Num2
{
public static void main (String []args)
{ int A[] = { 3,4,16,8,-9,10};
System.out.println(recAdd(A, 5));
}
public static int recAdd(int A[], int n)
//n is the index of the last element
{
}
}](https://image.slidesharecdn.com/writeamethodcalledrecaddthatwilladdtheintegerele-230322052735-7d11a5e9/75/Write-a-method-called-recAdd-that-will-add-the-integer-ele-pdf-1-2048.jpg)
The document describes the creation of a method called 'recadd' to sum the integer elements of an array. It provides an example with an array of integers and specifies the parameters for the method, including the array and the index of the last element. The document includes a basic Java class structure where the 'recadd' method will be implemented.
![Write a method called recAdd that will add the (integer) elements of an array. For example if the
array were {4,8,10} the method would return 22. Note the method will need to take as parameter
the array and also the index of the last element.
public class Lab14Num2
{
public static void main (String []args)
{ int A[] = { 3,4,16,8,-9,10};
System.out.println(recAdd(A, 5));
}
public static int recAdd(int A[], int n)
//n is the index of the last element
{
}
}](https://image.slidesharecdn.com/writeamethodcalledrecaddthatwilladdtheintegerele-230322052735-7d11a5e9/75/Write-a-method-called-recAdd-that-will-add-the-integer-ele-pdf-1-2048.jpg)