Write a program to display unique number.
Answers
Answered by
7
ANSWER
........................
{
static void teja(int num)
{
int m = num;
int dig;
int c;
int d=0;
int n = num;
int dig2;
int a = 0;
for(int i = 0;i<=9;i++)
{
m=num;
c=0;
while(m>0)
{
dig=m%10;
if(dig==i)
c++;
m/=10;
}
if(c==1)
d++;
}
while(n>0)
{
dig2 = n%10;
a++;
n/=10;
}
if(a==d)
System.out.println(num+” is a Unique Number “);
else
System.out.println(num+” is not a Unique Number “);
}
}
........................
{
static void teja(int num)
{
int m = num;
int dig;
int c;
int d=0;
int n = num;
int dig2;
int a = 0;
for(int i = 0;i<=9;i++)
{
m=num;
c=0;
while(m>0)
{
dig=m%10;
if(dig==i)
c++;
m/=10;
}
if(c==1)
d++;
}
while(n>0)
{
dig2 = n%10;
a++;
n/=10;
}
if(a==d)
System.out.println(num+” is a Unique Number “);
else
System.out.println(num+” is not a Unique Number “);
}
}
Answered by
1
import java.util.*;
class unique_number
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number to check whether it is unique number or not");
int n=sc.nextInt();
int cpy=n;
int d=0;
int c=0;
int flag=0;
for(int i=0;i<=9;i++)
{
n=cpy;
c=0;
while(n>0)
{
d=n%10;
if(d==i)
{
c++;
}
n=n/10;
}
if(c>1)
{
flag=1;
break;
}
}
if(flag==0)
{
System.out.println("Unique number");
}
else
{
System.out.println("Not a unique number");
}
}
}
Similar questions
Computer Science,
8 months ago
Computer Science,
8 months ago
Math,
8 months ago
Math,
1 year ago
Math,
1 year ago
Math,
1 year ago
Computer Science,
1 year ago