Search This Blog

Loading...

Sunday, November 23, 2014

BlueJ Program on Unique Digit Number



In this program, user will enter a number and the program will check whether it is an unique digit number or not. Unique digit number is a number where all the digits are unique, e.g 123, 1234 etc

The first program uses an array



import java.io.*;
class UDigit
{
int i,no,x=0,arr[];
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void takeNumber() throws Exception
{
 System.out.print("\nEnter the number:");
 no=Integer.parseInt(br.readLine());
 arr=new int[10];
 while(no >0)
 {
   for(i=0;i
   {
        if(no%10==arr[i])
        break;
    }
    if(i
    break;
    arr[x++]=no%10;
    no=no/10;
}
if(no >0)
System.out.println("\nNumber is not an unique digit number.");
else
System.out.println("\nNumber is an unique digit number.");
}

    public static void main(String args[])throws Exception
    {
       UDigit ob=new UDigit();
       ob.takeNumber();
        }
    }
     

The second program without any array

  
   import java.io.*;
class UDigit
{
int i,no,no1,no2,count;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void takeNumber() throws Exception
{
 System.out.print("\nEnter the number:");
 no=Integer.parseInt(br.readLine());
 no1=no;
 no2=no;
 while(no >0)
 {
  no1=no2;
  count=0;
  while(no1 >0)
  {
        if(no%10==no1%10)
       count++;
        no1=no1/10;
    }
    if(count >1)
    break;
    no=no/10;
}
if(no >0)
System.out.println("\nNumber is not an unique digit number.");
else
System.out.println("\nNumber is an unique digit number.");
}
    public static void main(String args[])throws Exception
    {
       UDigit ob=new UDigit();
       ob.takeNumber();
        }
    }

         

Monday, November 10, 2014

Engineering and Medical Entrance Examination 2015 Notification

CHECK HERE FOR PREVIOUS POSTS

Google+ Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner