英文句倒置

阅读更多
来自  javaeye

import java.util.StringTokenizer; 

public class Test{ 

    public static final String SEPARATORS = " ,\t:'';?!"; 

    public static String reverse(String input){ 
    
        StringTokenizer st = new StringTokenizer(input, SEPARATORS, true); 
        StringBuffer words = new StringBuffer(""); 
        while (st.hasMoreTokens()) { 
            words.insert( 0, st.nextToken() ); 
        }    
        return words.toString(); 
    }        
    
    public void testReverse(){ 
        
        String[] sentences = new String[]{ 
            "Hello, world!", 
            "I am a student", 
            "Am I a student? yes, or no", 
            "Am I a student ? yes , or no", 
            "Zhuang says:'It's just a coding game.'" 
            }; 
            
        for (int i = 0; i < sentences.length; i++) 
            System.out.println("Sentence[" + i + "]=[" + sentences[i]+"], " + 
                "After reversed: [" + Test.reverse(sentences[i])+"]"); 
        
    } 
    
    public static void main(String[] args){ 
        new Test().testReverse(); 
    } 
    
        
} 

你可能感兴趣的:(英文句倒置)