-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckString.java
More file actions
32 lines (32 loc) · 741 Bytes
/
CheckString.java
File metadata and controls
32 lines (32 loc) · 741 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
import java.util.*;
public class CheckString {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int flag=0;
String s=sc.nextLine();
StringBuilder sb=new StringBuilder(s);
for(int i=0;i<sb.length()-1;i++) { //to remove duplicate element
for(int j=i+1;j<sb.length();j++) {
if(sb.charAt(i)==sb.charAt(j)) {
sb.deleteCharAt(j);
i=sb.length();
break;
}
}
}
for(int i=0;i<sb.length()-1;i++) { //to check if still duplicate element exists
for(int j=i+1;j<sb.length();j++) {
if(sb.charAt(i)==sb.charAt(j)) {
flag=1;
i=sb.length();
break;
}
}
}
if(flag==1)
System.out.println("False");
else
System.out.println("True");
sc.close();
}
}