java - Perfect number method -


this program supposed take user input , determine whether or not perfect number. when try compile it, error method testperfect in class scalvert_perfect cannot applied given types;

  • testperfect(num);
  • required :int, int
  • found: int
  • reason: actual , formal argument list differ in length

my 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;          {         system.out.print("how many numbers test? ");         test = input.nextint();      }while(test < 1);          {         system.out.print("please enter possible perfect number: ");         num = input.nextint();          testperfect(num);         printfactors(num);          counter++;      }while(counter < test); }       public static boolean testperfect(int num, int test)     {         int sum = 0;          for(int = 0; < test ; i++)             {                 if(num % == 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 > 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 < num; factor++)                             {                                        x = num % factor;                                 if(x == 0)                                 {                                     system.out.printf("%d ",factor);                                 }                             }                                }                 system.out.print("\n");                 sum = 0;     }   } 

you function requires 2 integers because of this:

public static boolean testperfect(int num, int test) 

you call 1 integer here:

 testperfect(num); 

this way error says:

the function:

testperfect(num); 

needs 2 integers

required :int, int 

but called one:

found: int 

so error because amount of arguments not correct:

reason: actual , formal argument list differ in length 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -