Description. USE JAVA
Write a program that prints the largest element in a given integer
array.
Complete the program so that the output is the same as the given
output.
A given integer array is assumed to contain more than one
element.
[CONDITIONS]
The largest method should be executed recursively.
It can be written only in code template // your code here for
method largest.
A method or class other than largest cannot be added.
The code of the code template cannot be changed or changed.
Hint:
1) For the largest element in the array, divide the array in
half to find the largest element in each sub-array, and the largest
one is the answer.
no input
sample output:
code template:
public class Main {
public static void main(String[] args)
{
int[] data1 = {7, 5, 8, 2,
13, 6, 9, 15, 4};
int result1 = largest(data1,
0, data1.length - 1);
System.out.println(result1);
int[] data2 = {-12, 8, 3, 5,
7, 9, 4, 2};
int result2 = largest(data2,
0, data2.length - 1);
System.out.println(result2);
int[] data3 = {3};
int result3 = largest(data3,
0, data3.length - 1);
System.out.println(result3);
}
// your code for method largest
}
Description. USE JAVA Write a program that prints the largest element in a given integer array. Complete the program so
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am