Sunday, 25 August 2013

Actual and Formal arguments differ in length - don't know why

Actual and Formal arguments differ in length - don't know why

I'm a beginner Java programmer, and I have two simple files to solve a
simple math problem. One of them calls the other, which calculates the
factorial of the number (e.g. 4! = 24). For some reason, I can't call the
Factorial constructor.
Here is the calling class:
package Permutations;
import Permutations.Factorial;
public class Permutations {
public static void main(String args[]) {
System.out.println("There are 10 students. Five are to be chosen
and seated in a row for a picture. How many linear arrangements
are possible?");
System.out.println(new Factorial(10) / new Factorial(5));
}
}
Here is the Factorial class
package Permutations;
public class Factorial {
public long Factorial(int num) {
long result = 1;
for(int i = num; i > 0; i--)
result *= i;
return result;
}
}
Here is the error:
Permutations\Permutations.java:7: error: constructor Factorial in class
Factoria
l cannot be applied to given types;
System.out.println(new Factorial(10) / new Factorial(5));
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length
Permutations\Permutations.java:7: error: constructor Factorial in class
Factoria
l cannot be applied to given types;
System.out.println(new Factorial(10) / new Factorial(5));
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length
2 errors
I could change it to a static method, but then I would have to call it
with Factorial.Factorial(num) rather than new Factorial(num), which would
be inconvenient.
I have no idea why this is happening. Please help!
Thanks.

No comments:

Post a Comment