这条Java流的这一行是什么意思?
因此,我有这条代码。它给了我输出[6,28]。 你们知道为什么吗?我不知道有人试图打印什么数字。
System.out.println( IntStream.range(1,30).filter(n -> IntStream.range(1,n).filter(i->n%i == 0).sum() ==n)
.boxed().collect(Collectors.toList()));
So I have this line of code. It gives me output [6,28].
Do you guys know why? I dont know what kind of numbers was someone trying to print.
System.out.println( IntStream.range(1,30).filter(n -> IntStream.range(1,n).filter(i->n%i == 0).sum() ==n)
.boxed().collect(Collectors.toList()));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过检查
n
的所有除数,通过检查n
除以潜在的除数分隔(i-> n%i == 0
)。然后将所有除数求和与n
本身进行比较。我上面描述的是1到30之间的数字,并且只保留了比较为
true
的数字。因此,它计算出1到30之间的所有数字,其中除数总和到数字本身。这些称为完美的数字。前两个是6和28,其次是496,...calculates all the divisors of
n
by checking ifn
divided by the potential divisor has no remainder (i -> n % i == 0
). All divisors are then summed and compared withn
itself.Just does what I described above for the numbers between 1 and 30 and only keeps those where the comparison is
true
. It therefore calculates all the numbers between 1 and 30 where the divisors sum to the number itself. Those are called perfect numbers. The first two are 6 and 28, followed by 496, ...