Respuesta :
Answer:
// Here is code in java.
import java.util.*;
// class definition
class Solution
{
// main method of the class
public static void main (String[] args) throws java.lang.Exception
{
try{
// create two string and initialize them
String simon="RRGBRYYBGY";
String user="RRGBBRYBGY";
// variable to count score
int user_score=0;
// count the score of both strings
for(int i=0;i<10;i++)
{
if(simon.charAt(i)==user.charAt(i))
user_score++;
// if there is mismatch, loop breaks
else
break;
}
// print the score
System.out.println("user score:"+user_score);
}catch(Exception ex){
return;}
}
}
Explanation:
Create two string variables and initialize first with simon sequence and second with user sequence. Create a variable "user_score" to count the score of memory game.In the for loop, check each character of first string with Corresponding character of second string.If there is match then add 1 to user_score and if mismatch break the loop.Then print the user_score.
Output:
user score:4