-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniqueCharacters.java
More file actions
37 lines (32 loc) · 1000 Bytes
/
Copy pathUniqueCharacters.java
File metadata and controls
37 lines (32 loc) · 1000 Bytes
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
34
35
36
37
import java.util.Scanner;
public class UniqueCharacters {
static void checkUnique(char c[]){
boolean visited[]= new boolean[c.length];
int uniqueCount= 0;
for(int i=0; i<c.length; i++){
if (visited[i]== false){
int count= 0;
for(int j=i+1; j<c.length; j++){
if(c[i]==c[j]){
visited[j]= true;
count++;
}
}
if(count==0){
System.out.print(c[i] + " - ");
System.out.print(i + "\n");
uniqueCount++;
}
}
}
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
//STRING INPUT
System.out.print("Enter a string: ");
String s= sc.nextLine();
//CONVERT THE STRING TO CHAR ARRAY
char c[]= s.toCharArray();
checkUnique(c);
}
}