Note that there are some explanatory texts on larger screens.

plurals
  1. POPerfect number method
    primarykey
    data
    text
    <p>This program is supposed to take user input and determine whether or not it is a perfect number. When I try to compile it, I get the error Method testPerfect in class scalvert_Perfect cannot be applied to given types; </p> <ul> <li>testPerfect(num);</li> <li>required :int, int</li> <li>found: int </li> <li>reason: actual and formal argument list differ in length</li> </ul> <p>My code:</p> <pre><code>import java.util.Scanner; public class scalvert_Perfect { public static void main ( String args[] ) { Scanner input = new Scanner(System.in); int test; int num = 0; int counter = 0; do { System.out.print("How many numbers would you like to test? "); test = input.nextInt(); }while(test &lt; 1); do { System.out.print("Please enter a possible perfect number: "); num = input.nextInt(); testPerfect(num); printFactors(num); counter++; }while(counter &lt; test); } public static boolean testPerfect(int num, int test) { int sum = 0; for(int i = 0; i &lt; test ; i++) { if(num % i == 0) { sum += i; } } if(sum == num) { return true; } else { return false; } } public static void printFactors(int num) { int x; int sum = 0; for(int factor = num - 1 ; factor &gt; 0; factor--) { x = num % factor; if (x == 0) { sum = sum+factor; } } if(sum != num) { System.out.printf("%d:NOT PERFECT",num); } if(sum == num) { System.out.printf("%d: ",num); for(int factor=1; factor &lt; num; factor++) { x = num % factor; if(x == 0) { System.out.printf("%d ",factor); } } } System.out.print("\n"); sum = 0; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload