package cn.shen.shiyu;
/*
* 把一个英语句子中的单词次序颠倒后输出
*/
public class Inverse {
public void inverseWord(String str){
String[] wordArray=str.split(" ");
for(int i=wordArray.length-1;i>=0;i--){
System.out.print(wordArray[i]+" ");
}
}
}
package cn.shen.shiyu;
import java.util.Scanner;
import org.junit.Test;
public class InverseTest {
@Test
public void test() {
Scanner in=new Scanner(System.in);
System.out.println("请输入字符串,单词之间用空格隔开,按回车结束输入:");
String str=in.nextLine();
Inverse inverse=new Inverse();
inverse.inverseWord(str);
}
}