mardi 28 juillet 2020

Checking if two three digit numbers have any of there digits that are the same in Java

I'm trying to write a program in Java that checks if at least one digit of one of the numbers, matches one digit of the other number. For example, if the two numbers are 238 and 345 it should return a certain string.
So far this is what I have, but it only works properly for the right most digit:

if ((computerGuess/10) == (userGuess/10) || (computerGuess%10) == (userGuess%10) || (computerGuess%10) == (userGuess/10) || (userGuess%10) == (computerGuess/10)) {
                System.out.println("You have won S1000");
                break;
            }

Aucun commentaire:

Enregistrer un commentaire