Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Report: Java OCP 8 Programmer II Study Guide (Sybex)  RSS feed

 
Abdulaziz Akbary
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Chapter: 4, Page: 209, under the Table 4.8 in the example code, the last line

You have putted the result of sum in comment 15 I think that should be 35.

Regards,
Abdulaziz Akbary
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37180
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I see in my copy of the book:


5+10 is definitely 15. Does the example say something different in your book? And if so, what version are you using?
 
Abdulaziz Akbary
Greenhorn
Posts: 5
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, you are right,  I was thinking there is .range() method instead of .of() method

I was thinking like the following in that case i think the result should be 35

LongStream longs= LongStream.range(5, 10);
long sum = longs.sum();
System.out.println(sum); // 15


but in the book

LongStream longs= LongStream.of(5, 10);
long sum = longs.sum();
System.out.println(sum); // 15
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37180
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abdulaziz Akbary wrote:Sorry, you are right,  I was thinking there is .range() method instead of .of() method

Ah, so that's how you got 35. 5+6+7+8+9. That's two much math to make readers do . If I was using range as an example, I'd have done IntStream(1,4). And commentated on adding 1+2+3.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!