Hello Friends,
I have kept a very low profile on this forum, but for the past few weeks I have been reading as much about Java as I could. This is a language that I want to master, but in the process of creating a recursion, I can't seem to debug it so that it will compile successfully. For those of you who are familiar, this is a pretty popular example of a recursion called "Blastoff!" Here's what I have:
When I compile it, it says that I have three errors. They all read "class, interface, or enum expected."
Error I - Line 1
public static void main
^
Error II - Line 3
countdown(3);}
^
Error III - Line 13
}}}}
^
So being the diligent student that I am, I decided I would research the problem before I came whining to you guys about it. I figured it was a popular program and I copied it directly out of the book, so surely someone else has this problem. This is what I found:
This probably works, but I don't understand what is meant by" {countdown(Integer.parseInt (args[0]));} ." I read the original author's attempt to explain it, but I don't understand it well enough to see if it accomplishes the purpose of the assignment - which is to effectively write a recursion.
What I'm trying to do
What I'm trying to do is make countdown a class that is declared an integer value of three, and execute that class in main. In the execution of this class, the method possesses a nested conditional that invokes itself (a recursion). If it is the condition that n !=0, it's supposed to System.out.println the value of n and subtract 1 unit from the declared integer (3) each time it invokes itself until the condition that it reaches 0. When it reaches 0, System.out.println "Blast off!!!"
Can anybody give me a hand with this? I've looked at it for about two hours now and can't seem to debug properly.
EDIT - I fixed the third error by removing the extra bracket on line 13.