for(int i =0; i <=2; i++)
if you are in a class, and having an exam, then that means you should have been trying code, practicing, etc- all that aside- it means you should have an IDE (eclipse, netbeans, etc)
in short- you could have (and still can for extra practice/combinations) coded this real quick and seen the answer
you need to expose yourself to as many code situations as possible.
the code block for output puts in some extra line breaks after "end..." it would not do extras, just one