Skip to content

Instantly share code, notes, and snippets.

@isicju
Last active March 4, 2024 17:27
Show Gist options
  • Save isicju/5d3903d41fe4dae339c315a960438c78 to your computer and use it in GitHub Desktop.
Save isicju/5d3903d41fe4dae339c315a960438c78 to your computer and use it in GitHub Desktop.
Найдите сумму всех четных чисел.
public long makeOddNumberSum(Integer[] numbers){
// put your solution here
return 0l;
}
@isicju
Copy link
Author

isicju commented Mar 4, 2024

Solution using streams
// Your Java code goes here
import java.util.Arrays;

public long makeOddNumberSum(Integer[] numbers) {
    return Arrays.stream(numbers)
                 .filter(number -> number % 2 != 0)
                 .mapToLong(Integer::longValue)
                 .sum();
}

Some nice image:

cat-warriors-fights-agains-monster-in-ancient-worl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment