{public static void main(String[] args)
{
BufferedReader bufr=null;
BufferedWriter bufw=null;
try
{
bufr=new BufferedReader(new InputStreamReader(System.in));
bufw=new BufferedWriter(new OutputStreamWriter(System.out));
String line=null;
while((line=bufr.readLine())!=null)
{
char[] arr=line.toCharArray();
reverse(arr);
bufw.write(new String(arr));
bufw.newLine();
bufw.flush();
}
}
catch(Exception e)
{
throw new RuntimeException("读取失败");
}
finally
{try{if(bufr!=null)
bufr.close();
}
catch(Exception e)
{
throw new RuntimeException("读取关闭失败");
}
}
try{
if(bufw!=null){
bufw.close();
}
}
catch(Exception e)
{
throw new RuntimeException("输出关闭失败");
}
}
public static void reverse(char[] arr)
{for(int start=0,end=arr.length-1;start<end;start++,end--)
swap(arr,start,end);
}
public static void swap(char[] arr,int x,int y)
{char temp=arr[x];
arr[x]=arr[y];
arr[y]=temp;
}
}
|