Created
August 7, 2019 15:06
-
-
Save 0ryant/33ce2968499bdbd6a4ccf8d8d8c936fe to your computer and use it in GitHub Desktop.
Java - Coding Challenge - Do Two Numbers Share a Digit?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean hasSharedDigit(int num1, int num2) { | |
if ((num1 < 10) || (num1 > 99) || | |
(num2 < 10) || (num2 > 99)) { | |
return false; | |
} | |
for (int i = num1; i != 0; i /= 10) { | |
for (int j = num2; j != 0; j /= 10) { | |
if (i%10 == j%10) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment