-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecondOderIsogram.java
More file actions
45 lines (31 loc) · 1.34 KB
/
Copy pathSecondOderIsogram.java
File metadata and controls
45 lines (31 loc) · 1.34 KB
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
public class SecondOderIsogram{
public static void main(String... args) {
String phrase = "mallam";
System.out.print(isSecondOderIsogram(phrase));
}
public static boolean isSecondOderIsogram(String phrase){
boolean isPhraseWithOddOfCharacters = phrase.length() % 2 != 0;
if(isPhraseWithOddOfCharacters) return false;
String uniqueCharactersOfPhrase = "";
for(int index = 0; index<phrase.length(); index++){
char currentCharacter = phrase.charAt(index);
boolean isUniqueCharacterOfPhrase = !uniqueCharactersOfPhrase.contains("" + currentCharacter);
if (isUniqueCharacterOfPhrase){
uniqueCharactersOfPhrase += currentCharacter;
}
}
int numberOfUniqueCharacter = uniqueCharactersOfPhrase.length();
int[] tally = new int[numberOfUniqueCharacter];
for(int index = 0; index < numberOfUniqueCharacter; index++){
char currentCharacter = uniqueCharactersOfPhrase.charAt(index);
for(int counter = 0; counter < phrase.length(); counter++){
if(currentCharacter == phrase.charAt(counter))
tally[index] += 1;
}
}
for(int index = 0; index < tally.length; index++){
if(tally[index] != 2) return false;
}
return true;
}
}