Wednesday, 23 October 2013

Unique Number

import java.io.*;
 class Unique 
public static void main(String args[])throws IOException
 {
 BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
 int check=0,count=0,m,n,j,d,no_of_digits=0,num; 
System.out.println("\nINPUT:\n");
 System.out.print("m=");
 m=Integer.parseInt(in.readLine());
 System.out.print("n=");
 n=Integer.parseInt(in.readLine());
 System.out.print("UNIQUE DIGIT INTEGERS ARE:");//find unique numbers between m and n for(j=m;j<=n;j++) 
check=0; for(d=0;d<=9;d++) //this loop helps in checking digits from 0 to 9 { num=j; no_of_digits=0; while(num>0)//finding digits from number stored
 { 
int digit=num%10;
 if(digit==d)//check the equality of extracted digit and value of d
 {
 no_of_digits++;
 }//end if
 num=num/10;
 }//end while loop
 if(no_of_digits>1) 
{
 check=1;
 break;//from here control goes out of for d loop 
}//end if 
}//end of d loop 
if(check==0)//here check=0 means digits of the number is not repeating so it is unique
 { 
System.out.print(j+" ");
 count++; 
}//end if
 }//end for j loop 
System.out.println("\n\nFREQUENCY OF UNIQUE DIGIT INTEGERS ARE:"+count); }//end of main }//end class

No comments:

Post a Comment