Choose the best option based on this program:
import java.util.OptionalInt; import java.util.stream.IntStream; public class Main { public static void main(String args[]) { maxMarks(IntStream.of(52,60,99,80,76)); // #1 }/* ww w. j a v a 2 s . c om*/ public static void maxMarks(IntStream marks) { OptionalInt max = marks.max(); // #2 if(max.ifPresent()) { // #3 System.out.print(max.getAsInt()); } } }
C.
the ifPresent()
method in Optional takes a Consumer<T> as the argument.
this program uses ifPresent()
without passing an argument and hence it results in a compiler error.
If the method isPresent()
were used instead of ifPresent()
in this program, it will compile cleanly and print 99 on the console.