package perfect;
import java.math.BigInteger;
import java.util.Scanner;
public class Perfect {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter the number");
BigInteger n = input.nextBigInteger();
BigInteger sum = BigInteger.valueOf(0);
BigInteger i = BigInteger.valueOf(1);
BigInteger mul = BigInteger.valueOf(1);
for(; i.compareTo(n)< 0; i.add(BigInteger.ONE))
{
if(n.mod(i).equals(BigInteger.ZERO))
{
sum = sum.add(i);
mul = mul.multiply(i) ;
}
}
if(sum == n)
{
System.out.println(n+ "=" +mul) ;
}
else
{
System.out.println("the given number " +n+ " is not a perfect
number");
}
}
}
因为它必须打印 6 = 1*2*3,所以我使用了 BigInteger。但它没有显示任何错误,但程序在控制台中从用户那里获取数字后我没有得到任何输出。