Ask Question
23 December, 05:31

java The maximum-valued element of an integer-valued array can be recursively calculated as follows: If the array has a single element, that is its maximum (note that a zero-sized array has no maximum) Otherwise, compare the first element with the maximum of the rest of the array- - whichever is larger is the maximum value. Write an int method named max that accepts an integer array, and the number of elements in the array and returns the largest value in the array. Assume the array has at least one element.

+4
Answers (1)
  1. 23 December, 05:44
    0
    see explaination

    Explanation:

    MaxArray. java

    public class MaxArray{

    public static void main (String[] args) {

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

    int max = max (a, 5);

    System. out. println ("Max value is "+max);

    }

    public static int max (int a[], int size) {

    if (size > 0) {

    return Math. max (a[size-1], max (a, size-1));

    } else {

    return a[0];

    }

    }

    }

    Output:

    MaxArray
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “java The maximum-valued element of an integer-valued array can be recursively calculated as follows: If the array has a single element, ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers