I am making a Mastermind program.
I generate a random String with 4 numerical characters (characters cannot repeat themselves). For testing purposes, it's always 1234.
The user is then asked to guess the String by inputing 4 numbers.
I am making a method called PerfectMatches that checks how many guessed numbers are correct AND in the right position.
Here is my code :
public static int perfectMatches (String x, String y){
int i = 0;
int perfectmatches = 0;
for (i=0; i < 4; i++){
if ((x.charAt(i)) == (y.charAt(i))){
perfectmatches++;
}
I tried using if statements but I felt it wasn't efficient and took longer to process for the program.