Write the definition of a method named copy receives a reference to a Scanner object associated with a stream of input.

LANGUAGE: JAVA

CHALLENGE:

Write the definition of a method named copy receives a reference to a Scanner object associated with a stream of input. The method reads all the Strings remaining to be read from the stream and displays them, one on a line with no other spacing IN REVERSE ORDER, onto standard output. So if the input were:
here comes
the sun
the output would be:
sun
the
comes
here
The method must not use a loop of any kind (for, while, do-while) to accomplish its job.

SOLUTION:

public static void copy(Scanner input)
{
    String word;
    if(!input.hasNext())
    {
        return;
    }
    else
    {
	word = input.next();
	copy(input);
	System.out.println(word);
    }
}