forked from Sunchit/Coding-Decoded
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGoatLatin.java
More file actions
30 lines (22 loc) · 730 Bytes
/
GoatLatin.java
File metadata and controls
30 lines (22 loc) · 730 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
class GoatLatin {
public String toGoatLatin(String S) {
String[] words = S.split(" ");
StringBuilder newStr = new StringBuilder();
String a = "a";
for(String word : words) {
String newWord ="";
char startChar = word.charAt(0);
if(isVowel(Character.toLowerCase(startChar))){
newWord = word +"ma" + a;
} else{
newWord = word.substring(1) + startChar + "ma" + a;
}
newStr.append(" "+newWord);
a = a +"a";
}
return newStr.toString().substring(1);
}
private boolean isVowel(char c){
return (c=='a'|| c=='e'|| c=='i'|| c=='o'||c=='u');
}
}