在一小时前发布了一个较早的问题并在 4 分钟内得到了回复,这太疯狂了,我再试试运气。程序有 5 种方法,目前正在制作所有方法,因此它们不会都在这里(由于先前的响应而将其放入)问题现在是我最后的方法之一,它实际上除了使打印语句正常工作之外. 该方法不完整,它不仅需要找到所述数字的因数,还必须将它们存储在数组中,将它们相加并确定数字是否完美。最后一个未显示的方法将打印出每个数字的实际数组(如果它有一个)。“testperfect”是我遇到问题的方法,在eclipse中我收到一个错误,说这个方法必须返回布尔类型的结果。. . 任何形式的帮助将不胜感激
import java.util.Scanner;
public class tgore_perfect
{
private static int count;
private static int perfect;
public static void main ( String args [])
{
count = getNum ();
//System.out.print(count);
boolean check = validateNum();
//System.out.print(check);
while (validateNum() == false)
{
System.out.print ("Non-positive numbers are not allowed.\n");
count = getNum();
}
if (validateNum() == true)
{
for ( int i = 0; i < count; i++ )
{
perfect = getPerfect();
testPerfect();
}
}
}
public static int getNum () //gets amount of numbers to process
{
Scanner input = new Scanner ( System.in );
int counter;
System.out.println ("How many numbers would you like to test? ");
counter = input.nextInt();
return counter;
}
private static boolean validateNum() //checks user input
{
if (count <= 0)
{
return false;
}
else
{
return true;
}
}
public static int getPerfect() //gets number to process
{
Scanner input = new Scanner ( System.in);
perfect = -1;
System.out.print ("Please enter a possible perfect number: ");
return perfect = input.nextInt();
}
public static boolean testPerfect() //tests the number to see if is perfect
{
int sum = 0;
int x = 0;
for( int i = 1; i < perfect; i++ )
{
if((perfect % i ) == 0 )
{
x = i;
sum += x;
}
if( x == perfect)
{
return true;
}
else
{
return false;
}
}
}
}