AJ Java Programs
Program 7:
PiglatinWhen in a word first character is moved to last and "ay" is added to it it becomes Piglatin
Lets See how to do it.
Syntax:
import java.io.*;class piglatin
{
public static void main(String args[])throws IOException
{
char ch;
String word="",str="";
int i;
String s;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a String");
s=br.readLine();
s=s.trim();
s=" "+s+" ";
for(i=1;i<s.length();i++)
{
ch=s.charAt(i);
if(ch!=' ')
word+=ch;
else if(s.charAt(i-1)!=' ')
{
StringBuffer sb=new StringBuffer(word);
sb.append(sb.charAt(0));
sb.append("ay");
sb.deleteCharAt(0);
word+=" ";
str+=sb.toString();
}
}
System.out.println("Original String is "+s);
System.out.println("Piglatin= "+str);
}
}
Tested Ok Program
If You Don't Understand anything or want any program please write your request in Comment Section
And Please Like The Post
Comments
Post a Comment