JetBrains Academy: Infinite streams - Kamil-Jankowski/Learning-JAVA GitHub Wiki

JetBrains Academy: Infinite streams

Powers of two:

Implement a method that returns a prepared stream of the first n powers of two starting from the number 1.

import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

class StreamUtils {

    public static Stream<Integer> generateStreamWithPowersOfTwo(int n) {
        return Stream.iterate(1, x -> x * 2).limit(n); // replace it with your code
    }
}

⚠️ **GitHub.com Fallback** ⚠️