Question 2-1

Suppose a user executes the following run() method.

public static void run() {
    String str = "arboreteum";
    int j = 0;
    for(int i = 0; i < str.length(); i++) {
        if(str.charAt(i) == 'r') {
            IO.print(str.substring(j, i));
            j = i + 1;
        }
    }
    IO.println(str.substring(j));
}
Show all the values taken on by the variables of the program.
i
j
What does the method print?

Solution

i  0  1  2  3  4  5  6  7  8  9 10
j  0  2        5
It prints ``aboeteum''.

Back to 8:00 Quiz 2