About Question enthuware.ocpjp.v8.2.2022 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
d0wnvk@gmail.com
Posts: 7
Joined: Wed Jun 06, 2018 6:46 am
Contact:

About Question enthuware.ocpjp.v8.2.2022 :

Post by d0wnvk@gmail.com »

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

is line //5 really returns 12 ?

I mean 4%2 == 0, which means
filter( i->4%2 != 0 ) returns false.

Where is I am wrong ?

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.2022 :

Post by admin »

An element will be removed from the stream if the condition is true. If i%2 is 0 then the condition is not true and so element will NOT be removed.
If you like our products and services, please help us by posting your review here.

evgeny.kruptsov
Posts: 1
Joined: Tue Jul 10, 2018 7:23 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.2022 :

Post by evgeny.kruptsov »

Please fix the explanation, result is 0 for the following snippet of code:

Code: Select all

IntStream is2 = IntStream.of(2, 4, 6); //4 
int y = is2.filter( i->i%2 != 0 ).sum(); //5 
System.out.println(y); //6 
Attachments
Снимок экрана 2018-07-18 в 15.15.39.png
Снимок экрана 2018-07-18 в 15.15.39.png (124.33 KiB) Viewed 3961 times

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.2022 :

Post by admin »

You are right. Fixed.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

stefanbanu
Posts: 3
Joined: Sun Mar 04, 2018 1:09 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.2022 :

Post by stefanbanu »

Hello,

not fixed, the result still showing 12 when should be 0.

try to fixed.

thank you,
Stefan

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.2022 :

Post by admin »

Fixed for sure now! :o
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests