Programming Examples
Java program to pass an integer as argument and check whether all digits in it are unique or not
Write a program to pass an integer as argument, and check whether all digits in it are unique or not.
Solution
class Unique
{
public 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”);
}
}
Output