Java program to check Unique Number

What is a Unique number?

A Unique number is a positive integer (without leading zeros)with no duplicate digitis.

For example: 7,135,214,5243 are all unique numbers 
whereas 33,3121,200 are not.



import java.util.*;

class Unique

{

public static void main(String args[])

{
Scanner  sc=new Scanner(System.in);

System.out.println("Enter a number :");

int n= sc.nextInt();

String s=integer.toString(n);

int l=s.length();

int flag=0,i,j;

for(i=0;i<l-1;i++)

{

for(j=i+1;j<l;j++)
{

if(s.charAt(i)==s.charAt(j))
{
flag=1;
break;
}

}}

if(flag==0)

System.out.println("It is an UniqueNumber");

else

System.out.println("It is not am UniqueNumber");

}}


OUTPUT:

Enter a number: 5673

It is an Unique number

Enter a number : 5675

It is not a Unique number







Comments

Popular posts from this blog

TOP 10 COLLEGES OF INDIA