Write a program in Java to take input from the user and check whether it is a unique number or not. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Write a program in Java to take input from the user and check whether it is a unique number or not.

A number is said to be unique if the frequency of its every individual digit is one. For example : 1234 is a unique number whereas 1212 is not a unique number becoz the frequency of both 1 and 2 is two.

4th Feb 2018, 9:42 AM
Vansh Chopra
Vansh Chopra - avatar
7 Answers
+ 13
0)if single digit , then unique else 1)take digits in an array 2)arrange the elements of array 3)check if arr [a] ==arr [a+1] ... then break & not a unique no.
4th Feb 2018, 10:18 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
Thank you very much...
4th Feb 2018, 6:37 PM
Vansh Chopra
Vansh Chopra - avatar
+ 3
It works and I have just posted the program of an unique number...
4th Feb 2018, 6:38 PM
Vansh Chopra
Vansh Chopra - avatar
+ 3
Yeah, that's GREAT.
4th Feb 2018, 6:55 PM
Vansh Chopra
Vansh Chopra - avatar
+ 2
Is it a home work problem? have you tried anything? if so please post the code
4th Feb 2018, 10:09 AM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
+ 2
copy the number into a temp number. Take a Boolean array of size 10. each element represents the presence of a digit. initialize the array with false for all elements. while the temp number is greater than zero take the last digit and update its status in the bool array. divide the temp number by 10. repeat this process till temp is greater than zero.
4th Feb 2018, 12:21 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
+ 2
Since you have you tried. Let me show you I would write. https://code.sololearn.com/c2Dw46o11DFU/#java, let me know if you have not understood anything.
4th Feb 2018, 6:52 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar