java8勾股定理实现

 Stream<int[]> stream= IntStream.rangeClosed(1,100).boxed().
                flatMap(
                        a->
                                IntStream.rangeClosed(a,100).
                                        filter(b->
                                                Math.sqrt(a*a+b*b)%1==0).
                                        mapToObj(b->
                                            new int[]{a, b, (int) Math.sqrt(a * a + b * b)}
                                        )
                );
        stream.forEach(a->
                System.out.println(a[0]+","+a[1]+","+a[2]));

    原文作者:孙达
    原文地址: https://zhuanlan.zhihu.com/p/42880508
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞