Implement a method that returns the max number in a collection using the iterator. It's guaranteed the collection always has at least one element.
Iterator and Iterable
Finding the max number
Report a typo
Sample Input 1:
1 3 8 4 5Sample Output 1:
8Write a program in Java 17
import java.util.*;
import java.util.stream.Collectors;
public class Main {
public static int findMaxByIterator(Iterator<Integer> iterator) {
// write your code here
}
/* Do not change code below */
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
final List<Integer> list = Arrays.stream(scanner.nextLine().split("\\s+"))
.map(Integer::parseInt)
.collect(Collectors.toList());
System.out.println(findMaxByIterator(list.iterator()));
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.