- #1
lypena35
- 18
- 0
I have tried a bunch of different ways to edit this problem. The user input is 4 and I keep getting a output of 8 or 0. I appreciate the help!
The problem is:
"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. Ex: The following patterns yield a userScore of 4:
simonPattern: RRGBRYYBGY
userPattern: RRGBBRYBGY
My code:
The problem is:
"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. Ex: The following patterns yield a userScore of 4:
simonPattern: RRGBRYYBGY
userPattern: RRGBBRYBGY
My code:
Code:
import java.util.Scanner;
public class SimonSays {
public static void main (String [] args) {
String simonPattern = "";
String userPattern = "";
int userScore = 0;
int i = 0;
userScore = 0;
simonPattern = "RRGBRYYBGY";
userPattern = "RRGBBRYBGY"; char s;
char u; for (i=0;i<10;i++) {
s = simonPattern.charAt(i);
u = userPattern.charAt(i);
if (s==u) {
userScore = userScore + 1;
continue;
}
}
System.out.println("userScore: " + userScore);
return;
}
}
Last edited by a moderator: