?? wordrevertion.java
字號:
import java.util.ArrayList;
import java.io.*;
public class WordRevertion{
public WordRevertion(){
}
public ArrayList<String> reverse(String origin){
int length=origin.length();
String prototype="";
ArrayList<String> resultList=new ArrayList();
resultList.add(origin);
if(origin.endsWith("s")){
if(origin.endsWith("ies")){
prototype=origin.substring(0,length-3)+"y";
resultList.add(prototype);
}
if(origin.endsWith("es")){
prototype=origin.substring(0,length-2);
resultList.add(prototype);
}
prototype=origin.substring(0,length-1);
resultList.add(prototype);
}
if(origin.endsWith("ing")){
if(origin.charAt(length-4)==origin.charAt(length-5)){
prototype=origin.substring(0,length-4);
resultList.add(prototype);
}
resultList.add(origin.substring(0,length-2)+"e");
resultList.add(origin.substring(0,length-3)+"e");
resultList.add(origin.substring(0,length-3));
}
if(origin.endsWith("ed")){
if(origin.charAt(length-3)==origin.charAt(length-4)){
prototype=origin.substring(0,length-3);
resultList.add(prototype);
}
if(origin.endsWith("ied")){
prototype=origin.substring(0,length-3)+"y";
resultList.add(prototype);
}
resultList.add(origin.substring(0,length-2)+"e");
resultList.add(origin.substring(0,length-2));
}
return resultList;
}
public static void main(String[]args){
WordRevertion wr=new WordRevertion();
try{
while(true){
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String originWord=br.readLine();
ArrayList resultList=wr.reverse(originWord.trim());
for(int i=0;i<resultList.size();i++){
System.out.print(resultList.get(i)+" ");
}
System.out.println();
continue;
}
}catch(IOException e){
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -