96%(26)25 out of 26 people found this document helpful
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.CHALLENGEACTIVITY3.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: RRGBRYYBGYuserPattern: RRGBBRYBGYimport 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;}}RuncheckAll tests passed
checkTesting simonPattern: RRGBRYYBGY and userPattern: RRGBBRYBGYYour outputuserScore: 4checkTesting simonPattern: RRRRRRRRRR and userPattern: RRRRRRRRRYYour outputuserScore: 9checkTesting simonPattern: YBYBYBRRRR and userPattern: GGGGGGGGGGYour outputuserScore: 0