Page 1 of 1

about question enthuware.ocpjp.ii.v11.2.2022

Posted: Wed Jun 26, 2019 11:32 am
by entitybean

Code: Select all

Identify the correct statements about the following code -  
IntStream is1 = IntStream.of(1, 3, 5);  //1 
OptionalDouble x = is1.filter(i->i%2 == 0).average(); //2 
System.out.println(x); //3  

IntStream is2 = IntStream.of(2, 4, 6); //4 
int y = is2.filter( i->i%2 != 0 ).sum(); //5 
System.out.println(y); //6  
Answer options 2 and 3 mention:

Code: Select all

Compilation failure only at //4
Compilation failure at //2 and //4
Sure that line 4 is asked for in the questions? would doubting line 5 with the filter condition not make more sense?
I think line 2 and 5 are the difficult spots, not line 1 and 4 where "only" a IntStream is defined.

Re: about question enthuware.ocpjp.ii.v11.2.2022

Posted: Wed Jun 26, 2019 1:14 pm
by admin
Yes, //5 would make more sense.
thank you for your feedback!