/*输入一个字符串,进行反转*/
import java.io.*;
class ReverseString
{
public static void main(String[] args)
{
BufferedReader br = null;
String line = null;
String str;
StringBuilder sb = new StringBuilder(); //创建一个容器
try
{
br = new BufferedReader(new InputStreamReader(System.in)); //创建控制台输入流
while ((line = br.readLine()) != null)
{
if(line.equals("over")) //判断如果为over则结束输入
break;
sb.append(line);//把输入的值添加到容器中
System.out.println(sb.reverse().toString()); //反转数据
sb.delete(0,sb.length()); //清空容器
}
}
catch (IOException e)
{
System.out.println(e.toString());
}
}
}
|
|