-
Notifications
You must be signed in to change notification settings - Fork 4
/
22.missing_alphabets.java
46 lines (39 loc) · 1.31 KB
/
22.missing_alphabets.java
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
38
39
40
41
42
43
44
45
46
import java.util.*;
/*
Developed By Ishan Jogalekar
Considering only lower case alphabets
*/
public class missing_alphabets {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
//input string and lower case string
String str,str1;
System.out.println("Enter String:");
str = in.nextLine();
str1 = str.toLowerCase();
in.close();
//input string to string array
String[] arr = str1.split("");
//Alphabets String
String[] alpha = "abcdefghijklmnopqrstuvwxyz".split("");
//creating hashsets s1 and s3 of strings to get difference
HashSet<String> s1 = new HashSet<>(Arrays.asList(arr));
HashSet<String> s2 = new HashSet<>(Arrays.asList(alpha));
//removing duplicate entries in oder to find missing alphabets
s2.removeAll(s1);
//Creating output
String output = s2.toString()
.replace(",","")
.replace("[","")
.replace("]","")
.trim();
//printing output
System.out.println("*****------Missing Alphabets------****");
if(output.isEmpty()){
System.out.println("No missing alphabets");
}
else{
System.out.println(output);
}
}
}