-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPanagram.java
57 lines (44 loc) · 1.37 KB
/
Panagram.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
47
48
49
50
51
52
53
54
55
56
57
public class Panagram {
public static void main(String[] args) {
char[] alphabet = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z'
};
String sentenceString = "The quick red fox jumps over the lazy brown dog";
char[] sentenceToTest = toCharArray(sentenceString);
int numOfMissingLetters = 0;
char[] missingLetters = new char[26];
for(int i = 0; i < alphabet.length; i++) {
// System.out.println(isFound('\n', sentenceToTest));
if(!isFound(alphabet[i], sentenceToTest)) {
missingLetters[numOfMissingLetters] = alphabet[i];
numOfMissingLetters ++;
}
}
if(numOfMissingLetters == 0) {
System.out.println("\'"+ sentenceString.toString() +"\'"+ ' ' + "is an Anagram");
}
}
static Boolean isFound(char letter, char[] aSentence) {
Boolean found = false;
int iterator = 0;
while(!found) {
if(letter == aSentence[iterator]) {
found = true;
}
if(iterator == aSentence.length -1 ) {
break;
}
iterator++;
}
return found;
}
static char[] toCharArray(String sentence){
int sentenceLength = sentence.length();
char[] returnArray = new char[sentenceLength];
for(int i = 0; i < sentenceLength; i++) {
returnArray[i] = sentence.charAt(i);
}
return returnArray;
}
}