-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPigLatin.java
More file actions
36 lines (36 loc) · 1.05 KB
/
PigLatin.java
File metadata and controls
36 lines (36 loc) · 1.05 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
/* You have two friends who are speaking Pig Latin to each other! Pig Latin is the same words in the same order except that you take the first letter of each word and put
it on the end, then you add 'ay' to the end of that. ("road" = "oadray")
Sample Input
"nevermind youve got them"
Sample Output
"evermindnay ouveyay otgay hemtay"
*/
import java.util.*;
public class PigLatin{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String input = in.nextLine();
String str[] = input.split(" ");
char temp = 'a';
for (int i = 0;i<str.length ;i++ ) {
char words[] = str[i].toCharArray();
for (int j = 0;j<words.length ;j++ ) {
if (j==0) {
temp = words[j];
}
else if(j==(words.length)-1){
words[j-1] = words[j];
words[j] = temp;
}
else{
words[j-1] = words[j];
}
}
String newStr = String.valueOf(words);
newStr = newStr+"ay";
str[i] = newStr;
}
String joined = String.join(" ", str);
System.out.println(joined);
}
}