80.7k views
3 votes
Consider the following method.

public String mystery(String input)
{
String output = "";
for (int k = 1; k < (); k = k + 2)
{
output += input.substring(k, k + 1);
}
return output;
}

What is returned as a result of the call mystery("computer") ?

User ANISUNDAR
by
8.3k points

1 Answer

7 votes

Final answer:

The method 'mystery' takes a string as input and returns the characters at odd indices.

Step-by-step explanation:

The method mystery takes a string input, and for each character at an odd index (starting from 1), it appends it to the output string. In other words, it retrieves all the characters at odd positions from the input string and concatenates them together.

Since the method is called with the argument "computer", the characters at odd indices would be 'o', 'm', 't'. Therefore, the result of the mystery("computer") method call would be "omt".

User Jurglic
by
8.0k points