# 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

1 answer

###### Question:

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.

## Answers

Answer:see explaination Explanation:MaxArray.javapublic 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

#### Similar Solved Questions

2 answers

### Andreas drew the model below to represent the equation 20 + 10 = blank x (4 + 2). A model with 5 rows of 4 and 5 rows of 2. What is the missing value in Andreas’s equation? 2 4 5 6

Andreas drew the model below to represent the equation 20 + 10 = blank x (4 + 2).
A model with 5 rows of 4 and 5 rows of 2.
What is the missing value in Andreas’s equation?
2
4
5
6...

1 answer

### Give two examples of electrical energy being transformed in to another type of energy.Tell what energy is produced

Give two examples of electrical energy being transformed in to another type of energy.Tell what energy is produced...

1 answer

### A car accelerates from rest at a constant rate of 2m/s2 for 5s. what is the speed of a car at the end of that time?

A car accelerates from rest at a constant rate of 2m/s2 for 5s. what is the speed of a car at the end of that time?...

1 answer

### What is Julius Caesars nemesis in Julius Caesar? (Nemesis- the main hero's tragic flaw)

What is Julius Caesars nemesis in Julius Caesar?
(Nemesis- the main hero's tragic flaw)...

2 answers

### I have a cédille to make me soft, even though I can be tough and strong. Answer has 6 letters

I have a cédille to make me soft, even though I can be tough and strong. Answer has 6 letters...

1 answer

### Mexico’s war of independence from Spain in 1821 resulted in a political system that _____. A. was a one-party dictatorship controlled by the criollos B. favored peasants and the middle class C. was dominated by military dictators D. was a federal republic based on the system in the United States

Mexico’s war of independence from Spain in 1821 resulted in a political system that _____.
A. was a one-party dictatorship controlled by the criollos
B. favored peasants and the middle class
C. was dominated by military dictators
D. was a federal republic based on the system in the United States...

1 answer

### Sa piajes egne baseball games this season. Her point totais for each game were 8. 14.4 7.6.14, 4 and 7. What was the mean number of points she scoret per game?

Sa piajes egne baseball games this season. Her point totais for each game were 8. 14.4 7.6.14, 4 and 7. What was
the mean number of points she scoret per game?...

1 answer

### Viewed from earth two stars form an angle of 83.23 degrees. Star A is 33 light years from earth, and star B is 21 light years from earth. sketch a diagram modeling this situation and find out how many light years the stars are away from each other.

Viewed from earth two stars form an angle of 83.23 degrees. Star A is 33 light years from earth, and star B is 21 light years from earth. sketch a diagram modeling this situation and find out how many light years the stars are away from each other....

1 answer

### Which of the following statement regarding heat transfer through stationary fluid is correct? Select one: a. Conduction occurs when temperature gradient exists in stationary fluid Ο b. Convection occurs when temperature gradient exists in stationary fluid Ο c. Radiation occurs when temperature gradient exists in stationary fluid d. No heat transfer occurs when temperature gradient exists in stationary fluid

Which of the following statement regarding heat transfer through stationary fluid is correct? Select one: a. Conduction occurs when temperature gradient exists in stationary fluid Ο b. Convection occurs when temperature gradient exists in stationary fluid Ο c. Radiation occurs when temperature gra...

2 answers

### 10. What type of verb is jugar? O stem-changing compound O regular O irregular

10. What type of verb is jugar?
O stem-changing
compound
O regular
O irregular...

1 answer

### How many days would it take for a tiger to eat the eland antelope

How many days would it take for a tiger to eat the eland antelope...

1 answer

### Mrs. Weckerly is making chocolate chip cookies and the recipe calls for 3/4 cup of chocolate chips. If she wants to make 2/3 of the recipe, what fraction of a cup of chocolate chips will she need?

Mrs. Weckerly is making chocolate chip cookies and the recipe calls for 3/4 cup of chocolate chips. If she wants to make 2/3 of the recipe, what fraction of a cup of chocolate chips will she need?...

1 answer

### I'm in school and i need help cause I really bad at this : P

I'm in school and i need help cause I really bad at this : P...

2 answers

### What is the decimal multiplier to increase by 5.3%?

What is the decimal multiplier to increase by 5.3%?...

2 answers

### What is diffusion? A. The mixing of gas molecules due to random motion B. The force created when gas molecules hit their container C. The total number of molecules within a volume of gas D. The space occupied by gas molecules moving around

What is diffusion?
A. The mixing of gas molecules due to random motion
B. The force created when gas molecules hit their container
C. The total number of molecules within a volume of gas
D. The space occupied by gas molecules moving around...

1 answer

### Find the perimeter of the figure below, in inches.

Find the perimeter of the figure below, in inches....

2 answers

### Which of the following narrative techniques is used in the passage? "More bold than a man," she was Virgil's dux foemina facti, "the woman leading all the action" —the breeder and nourisher of all the county's distempers, the sower of political and religious discord. a. vivid details b. literal language c. sharing people's inner thoughts d. figurative language i will give the brainliest answer to the person that explains their answer with the best reasoning

Which of the following narrative techniques is used in the passage?
"More bold than a man," she was Virgil's dux foemina facti, "the woman leading all the action" —the breeder and nourisher of all the county's distempers, the sower of political and religious discord.
a. vivid details
b. literal la...