Limited access

Upgrade to access all content for this subject

Consider the following code.

String s = "weather";
String[] letters = new String[s.length()];

for (int i=0; i<s.length(); i++)
{
    if (s.substring(i,i+1).compareTo(s.substring(s.length()-i-1, s.length()-i)) < 0)
        letters [i] = s.substring(s.length()-i-1);
    else
        letters [i] = s.substring(i);
}

How many elements in the letters array contain the letter "t" after this code is executed?

A

5

B

4

C

3

D

1

E

0

Select an assignment template