Description. USE JAVA Please write according to the code template Write a program that prints the largest element in a g

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Description. USE JAVA Please write according to the code template Write a program that prints the largest element in a g

Post by answerhappygod »

Description. USE JAVA Please write according to the code
template
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

}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply