3.12.5. Mixed Up Code Practice

        lab-1e-1: The following program segment should print 4 random responses using if/else statements,  but the blocks have been mixed up.  Drag the blocks from the left and put them in the correct order on the right.  Click the Check Me button to check your solution.

private String getRandomResponse() { --- final int NUMBER_OF_RESPONSES = 4; double r = Math.random(); --- int whichResponse = (int)(r * NUMBER_OF_RESPONSES); String response = ""; --- if (whichResponse == 0) { response = "Interesting, tell me more."; --- } else if (whichResponse == 1) { response = "Hmmm."; --- } else if (whichResponse == 2) { response = "Do you really think so?"; --- } else if (whichResponse == 3) { response = "You don't say."; } --- return response; --- }
You have attempted of activities on this page
Next Section - 4. Iteration (Loops)