-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpig_latin.java
42 lines (42 loc) · 1.09 KB
/
pig_latin.java
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
32
33
34
35
36
37
38
39
40
41
42
import java.util.*;
class pig_latin
{
void main()
{
Scanner ob=new Scanner(System.in);
String n,s="", str="",x="",y="",newstr="";
char ch,ch1;
int i,k,len,len2;
System.out.println("Enter a sentence");
n=ob.nextLine();
n=n.toUpperCase();
System.out.println("The original sentence is:"+n);
len=n.length();
for(i=0;i<len;i++)
{
ch=n.charAt(i);
if(ch!=' ')
{
s=s+ch;
}
else
{
len2=s.length();
for(k=0;k<len2;k++)
{
ch1=s.charAt(k);
if(ch!='A'||ch1!='E'||ch1!='I'||ch1!='O'||ch1!='U')
break;
}
x=s.substring(0,k);
y=s.substring(k);
str=y+x+"AY";
newstr=newstr+str+" ";
s="";
len2=0;
x=y=str="";
}
}
System.out.println("new string is: "+newstr);
}
}