How to Solve the “To square(root) or not to square(root)” Challenge in Java
The challenge
Write a method, that will get an integer array as parameter and will process every number from this array.
Return a new array with processing every number of the input-array like this:
The input array will always contain only positive numbers and will never be empty or null.
Test cases
|
|
The solution in Java
Option 1 (using a loop
):
|
|
Option 2 (using a stream
):
Option 3 (using an IntStream
):