Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Java 8

int total = iterate(0, n -> n + 1).map(x -> x*x).limit(10).sum();



As someone who last used Java 5, that's really amazing! Need to write some more modern Java one of these days.


Yes, you do. :-) Alternative Java 8 solution:

int total = IntStream.rangeClosed(1, 10).map(x -> x*x).sum();




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: