UNIQUE NUMBER WITHIN RANGE OF NUMBERS without reading zeros | ISC COMPUTER 2024 | survnor.blogspot.com
A unique digit integer is a positive integer(without
reading zeros) with no duplicate digits. For example 7, 135, 214 are all
unique-digit integer, whereas 33, 300, 3121 are not. Even two positive integers
m and n, where m<n. Write a program to determine how many unique digit
integers are there in the integers between m and n(both included) and out them.
The input contains two positive positive integers m and n. Assumed m<3000
and n<3000. You are required to output the number of unique digit integers
in the specified range along with their values in the format specified below.
Example 1:- Input:-
m=100, n=120
Output:- The
unique digit integer are:- 102, 103, 104, 105, 106, 107, 108, 109, 120.
Frequency of
unique digit integers:- 9.
Example 2:- Input:-
m=2520, n=2529
Output:-
The unique digit integers are:- Nil.
Frequency
of unique digit integers:- 0.
ALGORITHM
STEP 1:- Start.
STEP 2:- Declare unique as a class.
Declare and initialize variables like k, x, i, j, m, n, cß0, indexß0, arrß[].
STEP 3:- Declare accept as a method. Start
range store into ‘m’ and last range store into ‘n’.
STEP 4:- If ‘m’ is not less than ‘n’.
Repeat step 3, otherwise go to step 5.
STEP 5:- Declare display as a method.
Repeat the following steps by assigning values starting from ‘m’ up to ‘n’ on
‘i’.
STEP 6:- Set zero on ‘index’ and ‘c’.
STEP 7:- Assign the value of ‘i’ on ‘j’ and
repeat the following steps until ‘j’ becomes zero.
STEP 8:- Retrieve a digit from ‘j’ and
check it whether it is present in the array ‘arr’
STEP 9:- If it is present, go to step 5.
STEP 10:- If not present assign the digits
in the array ‘arr’ and increment ‘index’ by ‘1’.
STEP 11:- Eliminate the digit from ‘j’ and
go to step 9.
STEP 12:- If ‘j’ becomes zero, display the
value of ‘i’ and increment ‘c’ by 1.
STEP 13:- Go to step 5, if ‘i’ becomes
greater than ‘n’, then go to step 14.
STEP 14:- Display ‘c’
STEP 15:-Declare main() and create object
ob of class unique. Call the accept() and display() object ob within main
function.
STEP 16:- Stop.
SOURCE CODE
import
java.util.*;
class
unique{
int k,x,i,j,m,n,c=0,index=0;
int arr[]=new int[1000];
Scanner sc=new Scanner(System.in);
void accept()//Declare accept as a method
with return type void{
while(true){
System.out.println("ENTER THE
START RANGE AND END RANGE:");
m=sc.nextInt();
n=sc.nextInt();
if(m<n)
break;}}
void display()//Declare display as a method
with return type void{
System.out.println("THE UNIQUE
DIGIT QUESTION ARE:");
for(i=m;i<=n;i++){
index=0;
for(j=i;j>0;j=j/10){
x=j%10;
for(k=0;k<index;k++){
if(arr[k]==x)
break;}
if(k<index)
break;
else
arr[index++]=x;}
if(j==0){
c++;
System.out.print("
"+i);}}
System.out.print("\nFREQUENCY OF
UNIQUE DIGITS INTEGER IS:"+c);}
public static void main(){
unique ob=new unique();
ob.accept();
ob.display();}}
VARIABLE DESCRIPTION
S.L.NO. |
NAME |
DATA TYPE |
DESCRIPTION |
1 |
m |
int |
It will hold the starting range. |
2 |
n |
int |
It will hold the ending range. |
3 |
i, j, k |
int |
These are loop control variable. |
4 |
n |
int |
It is used to hold digits. |
5 |
c |
int |
It is the counter to count unique
digit numbers |
6 |
arr[] |
int |
It is used to check the numbers
for unique digit. |
7 |
index |
int |
It is the array index of the array
arr[]. |
INPUT AND
OUTPUT