UNIQUE NUMBER IN JAVA // BLUEJ


Program in java to check if number is Unique number or not. 

(A Unique number is a number in which no repeated digits are present e.g.1234 it is a unique number while 12113 is not a unique number.)


***************************************

import java.util.Scanner;
class Unique_Number
{
   public static void main(String args[])
   {
      int n;int flag=1;
      Scanner in=new Scanner(System.in);
      System.out.print(“Enter a number:>”);
      n=in.nextInt();
      int c;
      int no=n;
       
      for(int i=0;i<=9;i++)
     {
         n=no;
         c=0;
         while(n>0)
        {
          int d=n%10;
          if(d==i)
          c++;
          n/=10;
        }
    if(c>1)
    flag=0;
    }

if(flag==1)
System.out.println(“It is a Unique number”);
else
System.out.println(“It is not a Unique number”);
  }
}

***************************************

Bluej Hub