Consider the following recursive method. public static void whatsItDo(String str) { int len = str.length(); if (len > 1) { String temp = str.substring(0, len – 1); System.out.println(temp); whatsItDo(temp); } } What is printed as a result of the call whatsItDo("WATCH")?

Respuesta :

tonb

Answer:

It prints:

WATC

WAT

WA

W

Explanation:

The function prints the input string minus the last character, then calls itself.

You can easily run this on https://repl.it/languages/java10

Ver imagen tonb

The output when the recursive method is executed is

  • WATC
  • WAT
  • WA
  • W

How to determine the code output?

The flow of the code is to print the characters of the string from -1 index to the 0 index.

The string passed to the function is "WATCH"

So the code would print "WATC" to "W", each on a new line

Hence, the output when the recursive method is executed is

  • WATC
  • WAT
  • WA
  • W

Read more about recursive methods at:

https://brainly.com/question/24167967

#SPJ2