The loop will iterate only once True False Correct The loop will iterate 5

The loop will iterate only once true false correct

This preview shows page 2 - 3 out of 3 pages.

2)The loop will iterate only once. TrueFalseCorrectThe loop will iterate 5 times. Continue jumps to the next iteration, thus preventing each iteration fromprinting anything, but it doesn't break out of the loop. CHALLENGE ACTIVITY 3.21.1: Simon says. "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement. Assume simonPattern and userPattern are always the same length. Ex: The following patterns yield a userScore of 4: simonPattern: RRGBRYYBGY userPattern: RRGBBRYBGY import java.util.Scanner; public class SimonSays { public static void main ( String [] args) { Scanner scnr = new Scanner( System .in); String simonPattern; String userPattern; int userScore; int i; userScore = 0 ; simonPattern = scnr.next(); userPattern = scnr.next(); for (i = 0 ; i < simonPattern.length(); i ++ ) { if (simonPattern.charAt(i) == userPattern.charAt(i)) { userScore ++ ; } else { break ; } } Run check All tests passed
Image of page 2
check Testing simonPattern: RRGBRYYBGY and userPattern: RRGBBRYBGY Your output userScore: 4 check Testing simonPattern: RRRRRRRRRR and userPattern: RRRRRRRRRY Your output userScore: 9 check Testing simonPattern: YBYBYBRRRR and userPattern: GGGGGGGGGG Your output userScore: 0
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • Summer '14
  • Control flow, simonPattern

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture