题解 | #句子逆序#
句子逆序
http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
最重要的是str.split(),按字符分割成一个一个小元素
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String str = scan.nextLine();
String[] strs = str.split(" ");
int size = strs.length;
String t = "a";
for(int i = 0; i<size/2; i++){
t = strs[i];
strs[i] = strs[size - 1-i];
strs[size-1-i] = t;
}
for(String s : strs){
System.out.print(s+ " ");
}
}
}
}