Each of the counter-controlled for loops we used in this chapters examples can be implemented using IntStreams

Question:

Each of the counter-controlled for loops we used in this chapter’s examples can be implemented using IntStream’s rangeClosed method to produce a range of values, then using IntStream’s forEach method to specify a lambda to execute for each value. The lambda argument to forEach could, for example, call method factorial (Figs. 18.3 –18.4) or method fibonacci (Fig. 18.5 ) and display the result.

Figs. 18.31 // Fig. 18.3: Factorial Calculator.java // Recursive factorial method. 2 3 4 public class Factorial

Figs. 18.4

I // Fig. 18.4: Factorial Calculator.java 2 // Recursive factorial method. 3 import java.math.BigInteger; 4 5

Figs. 18.5I // Fig. 18.5: FibonacciCalculator.java // Recursive fibonacci method. import java.math.BigInteger; 23456780

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Java How To Program Late Objects Version

ISBN: 9780136123712

8th Edition

Authors: Paul Deitel, Deitel & Associates

Question Posted: