-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDejaVu.java
More file actions
33 lines (33 loc) · 910 Bytes
/
Copy pathDejaVu.java
File metadata and controls
33 lines (33 loc) · 910 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
/*You aren't paying attention and you accidentally type a bunch of random letters on your keyboard. You want to know if you ever typed the same letter twice, or if they
are all unique letters.
Sample Input:
aaaaaaaghhhhjkll
Sample Output:
Deja Vu*/
import java.util.Scanner;
public class DejaVu{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("Enter the String");
String str = in.nextLine();
char ch[] = new char[str.length()];
for (int i=0;i<str.length() ;i++ ) {
ch[i] = str.charAt(i);
}
//checking if occurences are there
boolean flag = true;
for (int i=0;i<ch.length ;i++ ) {
for (int j=1;j<ch.length-1 ;j++ ) {
if (ch[j]==ch[j+1]) {
flag = false;
}
}
}
if (flag) {
System.out.println("Unique");
}
else{
System.out.println("Deja Vu");
}
}
}