I was wondering why in the following code for factorial, I needed to declare the factorial and iter methods static.
public class example_fact2{
public static void main(
String[]args){
System.out.println(factorial(7));
}
public static int factorial(int n){
return iter(1, 1, n);
}
private static int iter(int counter, int product, int n){
if(counter> n){
return product;
}
else{
return iter(counter+1, product*counter, n);
}
}
}