9:4
8:4
7:3
6:3
5:2
4:2
3:1
2:1
1:NOT PERFECT
I need it to also display the factors in descending order.
So here is my method to test:
public static boolean testPerfect(int number2)
{
int sum = 0;
boolean testing = false;
for (int i = 1; i < number2; i++ )
{
if ( i % number2 == 0)
sum = sum + i;
testing = true;
} return testing;
} // end testPerfect
I know something is messed in my for loop due to the return of all numbers, except #1, to display factors/modulus.
This is my method to print factors, which I think is all correct except for displaying ALL factor in descending order.
public static void printFactors(int print)
{
int total = 0;
for (int divisor = 1; divisor < print; ++divisor)
{
if(divisor == print/2)
{
System.out.printf("%d", divisor);
}
}
}
I know I need to decrement divisor, but when I do i get a infinite loop. Do I need to take the if statement out of the for loop?
As stated in the rules, I'm not looking for anyone to correct this for me just some help on where I need to fix my problems.
Thanks!

New Topic/Question
Reply



MultiQuote






|