Write a program to check whether the number entered by the user is a UNIQUE INTEGER or not. A UNIQUE INTEGER is one that has no repetition of digits. i.e. all the digits are distinct and appears only once. For e.g. 1234, 65234 etc.
Answers
Write a program to check whether the number entered by the user is a UNIQUE INTEGER or not. A UNIQUE INTEGER is one that has no repetition of digits. i.e. all the digits are distinct and appears only once. For e.g. 1234, 65234 etc.Write a program to check whether the number entered by the user is a UNIQUE INTEGER or not. A UNIQUE INTEGER is one that has no repetition of digits. i.e. all the digits are distinct and appears only once. For e.g. 1234, 65234 etc.// Java implementation to find unique digit
// numbers in a range
class Test
{
// Method to print unique digit numbers
// in range from l to r.
static void printUnique(int l, int r)
{
// Start traversing the numbers
for (int i=l ; i<=r ; i++)
{
int num = i;
boolean visited[] = new boolean[10];
// Find digits and maintain its hash
while (num != 0)
{
// if a digit occurs more than 1 time
// then break
if (visited[num % 10])
break;
visited[num%10] = true;
num = num/10;
}
// num will be 0 only when above loop
// doesn't get break that means the
// number is unique so print it.
if (num == 0)
System.out.print(i + " ");
}
}
// Driver method
public static void main(String args[])
{
int l = 1, r = 20;
printUnique(l, r);
}
}
Answer:
JAVA :-
Explanation:
class Brainly
{
static void main(int n)
{
int i,s=0,c=0,d,j,d1,f=0;
for(i=n;i>0;i=i/10)
{
d1=i%10;
for(j=i/10;j>0;j=j/10)
{
d=j%10;
if(d==d1)
f=1;
}
}
if(f==0)
System.out.println(“All digits are unique”);
else
System.out.println(“All digits are not unique”);
}
}