-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniqueNo.java
More file actions
33 lines (32 loc) · 1.22 KB
/
UniqueNo.java
File metadata and controls
33 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
public class UniqueNumber {
public static void main(String args[] ) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number you want to check:");
//reading an integer from the user
int number=sc.nextInt();
//converts integer data type into string
String str= Integer.toString(number);
//determines the length of the string
int length=str.length();
int flag=0, i, j;
//loop checks the digits are repeated or not
for(i=0;i<length-1;i++){
for(j=i+1;j<length;j++){
//comparing each digit, if digits are repeated the number is not unique
if(str.charAt(i)==str.charAt(j))
{
flag=1;
break;
}
}
}
//if flag is equal to zero the number is unique
if(flag==0)
System.out.println("The number is unique:"+number);
else
System.out.println("The number is not unique:"+number);
}
}
/**
* @author Pradumn Patel */