WRITE A PROGAM THAT ENCODES A WORD INTO "PIGLATIN".
Program that encodes a word into 'Piglatin'.
The following program segment demonstrates the above :
import java.util.*;
class piglatinWord
{
public static void main (String args[])
{
Scanner ob = new Scanner (System.in);
String str , beforeVow = "", afterVow = "";
System.out.println("enter a word");
str = ob.next();
String changedW = str.toUpperCase();
String Pigw = "";
int pos = 0;
int length = changedW.length();
for(int i = 0; i< length; i++)
{
char c = changedW.charAt(i);
if (c == 'A' ||c == 'E'||c == 'I'||c =='O'||c =='U')
{
pos = i;
beforeVow = changedW.substring(0, pos);
afterVow = changedW.substring(pos);
Pigw = afterVow +beforeVow+"AY";
System.out.println("output");
System.out.println("Capital word ="+changedW);
System.out.println("PIGLATIN WORD ="+Pigw);
}
}
if(pos ==0)
{
System.out.println("Vowel is not present in the string, so piglatin not found");
}
}
}
Comments
Post a Comment