📄 piglatin.java
字号:
import java.io.*;
public class PigLatin
{
static BufferedReader keyboard =new BufferedReader(new InputStreamReader(System.in));
public static Boolean isVowel(char ch)
{
switch(ch)
{
case 'A':case 'E':
case 'I':case 'O':
case 'U':case 'Y':
case 'a':case 'e':
case 'i':case 'o':
case 'u':case 'y': return true;
default:return false;
}
}
public static String rotate(String pStr)
{
int len=pStr.length();
String rStr;
rStr=pStr.substring(1,len)+pStr.charAt(0);
return rStr;
}
public static String pigLatinString(String pStr)
{
int len;
boolean foundVowel;
int counter;
if(isVowel(pStr.charAt(0)))
pStr=pStr+"-way";
else
{
pStr=pStr+"-";
pStr=rotate(pStr);
len=pStr.length();
foundVowel=false;
for(counter=1;counter<len-1;counter++)
if(isVowel(pStr.charAt(0)))
{
foundVowel=true;
break;
}
else
pStr=rotate(pStr);
if(!foundVowel)
pStr=pStr.substring(1,len)+"-way";
else
pStr=pStr+"ay";
}
return pStr;
}
public static void main(String[] args)throws IOException
{
String str;
System.out.print("enter a string:");
System.out.flush();
str=keyboard.readLine();
System.out.println();
System.out.println("the piglatin form of"+str+"is:"+pigLatinString(str));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -