Ask Question
30 July, 08:12

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.

+1
Answers (1)
  1. 30 July, 10:45
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers