参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); for(int a=6; a<=n; a++){ String t = ""; //存储需要输出的字符串 int sum = 0; for(int i=1; i<a; i++){ //整除即因子 if(a%i==0){ t+=i+" "; sum+=i; } } if(a==sum){ System.out.println(a+" its factors are "+t); } } } }
0.0分
5 人评分