Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

what would be the summation of this look like? public static void main ( String [ ] args ) { int [ ] array =

what would be the summation of this look like?
public static void main(String[] args){
int[] array ={16,17,4,3,5,2};
List dominantElement = findDomElement(array);
System.out.println(dominantElement);
}
public static List findDomElement(int[]array){
List dominantElement = new ArrayList<>();
int currMax = array[array.length -1];
dominantElement.add(currMax);
// having loop start at 5 & then going backwards
for (int i = array.length -2; i >=0; i--){
if (array[i]> currMax){
currMax = array[i];
dominantElement.add(currMax);
}
}
return dominantElement;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions