您可以幫助「刪除」該程序。 我有它幾乎完美,但是當我打印它包括「28」,我不想要。從程序中刪除不需要的文本
public static boolean isPerfectNumber(int n)
{
int lhs=0,rhs = 0;
for(int i = 1;i<(n-2);i++)
{
lhs += i * (n/i) ;
rhs += i * ((n-1)/i) ;
}
rhs += n;
if(rhs == lhs)
{
return true ;
}
return false ;
}
public static void main(String[] theory) {
int candArray[] = new int [20] ;
for(int i = 2;i<21;i++)
{
candArray[i-2] = (int) (Math.pow(2, i-1)*(Math.pow(2, i)-1) );
}
for(int i = 1;i<20;i++){
if(isPerfectNumber(candArray[i]) )
{
System.out.println(candArray[i] + " is a perfectNumber" );
}
}
}
你能確切地解釋(更清晰)你** **不想要? – ZnArK
當我運行程序時,它打印出「28是一個完美的數字」。我希望除了28之外的一切都是完美的數字。 – Fruitytart
28是一個完美的數字。你爲什麼不希望它被打印? – dlev