leetcode题解
(1)题目:
Given an input string, reverse the string word by word.
For example,
Given s = “the sky is blue”,
return “blue is sky the”.
使用java实现代码:
package leetcode;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class onecode {
public static void main(String[] args) throws IOException
{
BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));
System.out.print(“请输入一个字符串:”);
String str = strin.readLine();
String array[]=str.split(” “);
String printout=”“;
for(String item:array)
{
printout=item+” “+printout;
}
System.out.println(printout);
}
}