we got a task for the next week with Lambdas.
We should write some Lambdas without Control Flow Statements.
Example:
We got a string and this string should repeat n-times.
Example: (string,3)-> stringstringstring.
The common problem is, that we dont know, how to catch e.g. -9 or 0.
My code looks like this:
BiFunction<Integer, String, String> nAnhaengen
= (n, word) -> {
Stream.iterate(word, wordAdd-> word + wordAdd).
limit(n).
skip(n-1).
forEach(element -> System.out.println(element));
return "";
};
Have you an idea or tipps, how we can catch negative integers?
Thanks and Greetings Daniel