Calling non static method in static method : <p>I am having a little issue with my code. I am trying to find the runtime to compare to some math that I have prepared for the problem. I have one method in particular that I am testing that goes like this:</p>

<pre><code> public static int foo(int n, int k){
        long startTime = System.nanoTime();
        if(n&lt;=k){
            long endTime = System.nanoTime();
            System.out.println("checkFoo");
            System.out.println("start time: " +startTime);
            System.out.println("end time: " +endTime);
            return 1;
        }
        else{
            return foo(n/k,k) + 1;
        }
    }
</code></pre>

<p>I test this code in my main method in the following way: </p>

<pre><code>public static void main(String[] args){
    foo(1, 1);
    foo(5, 1); 
    foo(10, 1);
    foo(100, 1);
}
</code></pre>

<p>I get an error where it says </p>

<pre><code>Exception in thread "main" java.lang.StackOverflowError
</code></pre>

<p>and then it repeats the line:</p>

<pre><code>at Problem3.foo(Problem3.java:42) 
</code></pre>

<p>I am wondering if this has to do with the fact that foo is supposed to return an int and maybe I am just not calling the function correctly. If that is the case, what is considered the correct way to call this function so that it also prints out the information that I need it to? Or is this error completely different than how I am understanding it to be?</p>
