I'm having trouble understanding the concepts of static methods, and how to call them. Also how recursive methods work through.
for example, take this code:
public static void recur2 (int n) { if(n<=0) { return; } else { recur2(n - 2); System.out.print(n); } }
what does the method call recur2(5) display? Furthermore, this would be easy to just test and see what the result is, but I don't know how to call static methods.
Normally I would create some class and add the line "public static void main(String[] args)" which would be my driver class for whatever class I created to do some problem. So by that method I would create these two classes:
public class Test{ public static void recur2 (int n) { if(n<=0) { return; } else { recur2(n - 2); System.out.print(n); } } }
public class TestDriver{ public static void main(String[] args){ System.out.println(recur2(5)); } }
But that gives me an error saying this recur2(int) is undefined for the type TestDriver