I'm having a little trouble wrapping my head around this logic and thought I had a fix but am stumped now.
The goal is to create a 4 digit pin and have 3 unique numbers and 1 can be a duplicate. They can be in any order as well. Here is what i have so far:
boolean UniqueNums(String nums)
{
for (int i=0; i < 3; i++)
for (int j=i+1; j < 3; j++)
if (nums.charAt(i) == nums.charAt(j))
return false;
// If no duplicate characters encountered,
// return true
return true;
}
So if i pass the numbers 1137
it fails but other like 1371
pass.
I feel this is the different then the linked duplicate answer link, due to im not trying to do it in one line and I'm not just counting the number of times the number occurs. More a long the lines of validating the values being passed.
Any help or advice would be appreciated.