Question
print pig Latin form of a given sentence.
To translate a word into a Piglatin word, convert the word into uppercase and then place the first vowel of the original word as the start of the new word along with the remaining alphabets. The alphabets present before the vowel being shifted towards the end followed by “AY”.
Example:
London becomes ONDONLAY
cat becomes ATCAY
Enter the Sentence:
quick brown fox jumped over the lazy dog
Original Sentence:QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
New Sentence:UICKQAY OWNBRAY OXFAY UMPEDJAY OVERAY ETHAY AZYLAY OGDAY.
Enter the Sentence:
the capital of India is new Delhi.
Original Sentence:THE CAPITAL OF INDIA IS NEW DELHI.
New Sentence:ETHAY APITALCAY OFAY INDIAAY ISAY EWNAY ELHIDAY.
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class Piglatin
{
public static void main()
{
int i,len=0,j=0;
String sen="",newSen="",wd="",piglatinWd="";
char ch= ' ',ch1=' ';
boolean vowelFound=false;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Sentence:");
sen=sc.nextLine();
len=sen.length();
if(sen.charAt(len-1)!='.')
{
sen=sen+".";
len=len+1;
}
len=sen.length();
sen=sen.toUpperCase();
for(i=0;i< len;i++)
{
ch=sen.charAt(i);
if(ch==' '||ch=='.')
{
for(j=0;j< wd.length();j++)
{
ch1=wd.charAt(j);
if(ch1=='A'||ch1=='E'||ch1=='I'||ch1=='O'||ch1=='U')
{
vowelFound=true;
break;
}
}
if(vowelFound==true)
{
piglatinWd=wd.substring(j);
piglatinWd=piglatinWd+wd.substring(0,j)+"AY";
}
else
{
piglatinWd=wd+"AY";
}
newSen=newSen+piglatinWd+ch;
piglatinWd="";
wd="";
vowelFound=false;
}
else
{
wd=wd+ch;
}
}
System.out.println("Original Sentence:"+sen);
System.out.println("New Sentence:"+newSen);
}
}
Coding Store
Sale
ISC QUESTION PAPERS WITH SOLUTION(PROGRAMMING ONLY)
Sale