-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPigLatin.java
More file actions
31 lines (31 loc) · 1.14 KB
/
PigLatin.java
File metadata and controls
31 lines (31 loc) · 1.14 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
/*
Write a program that encodes a word into Pig Latin.
To translate word into a pig latin word, convert the word in
to Uppercase and then place the first vowel of the original word
as the start of new word along with the remaining alphabets.
The alphabets present before the vowel being shifted towards the end followed by “AY”.
Example: London ONDONLAY And Olympics OLYMPICSAY
*/
import java.io.*;
public class PigLatin
{
public static void main(String args[])throws IOException
{
BufferedReader a = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the string to be converted to Pig Latin : ");
String s = a.readLine();
int i = 0,d = 0;
for(i = 0;i<s.length();i++)
{
if("aeiouAEIOU".indexOf(s.charAt(i)) != -1) {
d = i;
break;
}
}
String s1 = s.substring(d);
String s2 = s.substring(0,d);
String output = s1+s2+"ay";
output = output.toUpperCase();
System.out.println("Your String converted to Pig Latin : "+output);
}
}