Challenge: Find Maximum and Minimum in Array
Task
Swipe to start coding
Your task is to write two methods: one to find the maximum value and one to find the minimum value in the array.
- In the
findMaxmethod, initialize themaxvariable with the first element of the array. - In the for loop, compare the current element with
max. - If the current element is greater, update
maxwith the current element. - Return the value of the
maxvariable. - In the
findMinmethod, initialize theminvariable with the first element of the array. - In the for loop, compare the current element with
min. - If the current element is smaller, update
minwith the current element. - Return the value of the
minvariable. - In the
mainmethod, call thefindMaxmethod with the correct parameter, pass thenumbersarray into it, and assign the result to themaxvariable. - In the
mainmethod, call thefindMinmethod with the correct parameter, pass thenumbersarray into it, and assign the result to theminvariable.
Solution
solution.java
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 8
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Suggested prompts:
Summarize this chapter
Explain the code in file
Explain why file doesn't solve the task
Awesome!
Completion rate improved to 2.63
Challenge: Find Maximum and Minimum in Array
Swipe to show menu
Task
Swipe to start coding
Your task is to write two methods: one to find the maximum value and one to find the minimum value in the array.
- In the
findMaxmethod, initialize themaxvariable with the first element of the array. - In the for loop, compare the current element with
max. - If the current element is greater, update
maxwith the current element. - Return the value of the
maxvariable. - In the
findMinmethod, initialize theminvariable with the first element of the array. - In the for loop, compare the current element with
min. - If the current element is smaller, update
minwith the current element. - Return the value of the
minvariable. - In the
mainmethod, call thefindMaxmethod with the correct parameter, pass thenumbersarray into it, and assign the result to themaxvariable. - In the
mainmethod, call thefindMinmethod with the correct parameter, pass thenumbersarray into it, and assign the result to theminvariable.
Solution
solution.java
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 8
single