leetCode题解

来源:互联网 发布:钱咖试客类似的软件 编辑:程序博客网 时间:2024/04/28 04:11

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);
}
}

0 0