-->
当前位置:首页 > 题库 > 正文内容

程序填空题:Perfect Numbers

Luz4年前 (2021-05-10)题库1341
A perfect number is a number that the sum of all factors (itself excluded) equals itself. For example, 6 is a perfect number because `1+2+3 = 6`.

This program reads two integers a and b, where `0
```Java
import java.util.stream.IntStream;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int[] r =
IntStream.range(a, b).
filter( @@[x->IntStream.range(1,x).filter(k->x%k==0).sum()==x](5) ).
toArray();
for ( int x : r ) {
System.out.print(x+" ");
}
System.out.println();
in.close();
}
}
```






答案:
第1空:x->IntStream.range(1,x).filter(k->x%k==0).sum()==x

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。