WAP to input a string and change it to PigLatin string.
=============================
import java.util.Scanner;
public class PigLatinWord
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int length;
String piglatin="" , pre="" , post="";
char tmpChar;
int posVowel= -1;
System.out.println(" ENTER A STRING");
String st = sc.nextLine();
st = st.toUpperCase();
length= st.length();
for (int i=0; i<=length; i++)
{
tmpChar= st.charAt(i);
if( tmpChar=="A" || tmpChar=='E'||tmpChar=='I'||tmpChar=='O'||tmpChar=='U')
{
posVowel = i; System.out.println("Position:"+posVowel);
break;
}
}
if ( posVowel >= 0)
{
pre = st.substring(0, posVowel);
post = st.substring(posVowel);
piglatin = pos + pre + "AY";
System.out.println("PigLatin of" + st + "is" + piglatin );
}
else
{
System.out.println("No vowels found");
}
}
}
===============================
Sample Output :
ENTER A STRING
London
ONDONLAY
===============================
0 Comments