re: Daily Challenge #88 - Recursive Ninjas VIEW POST

FULL DISCUSSION
 

Java

        public static void chirp(int i)
        {
                if (i == 1)
                        System.out.println("chirp");
                else if (i > 1) {
                        System.out.print("chirp-");
                        chirp(i - 1);
                }
        }

Note that this assumes a few things:

  • We want a carriage return at the end of the string.
  • The correct response to chirp(i) for i < 1 is silence.
  • The value of i is not going to be large enough for us to be worried about blowing the stack.
code of conduct - report abuse