0
点赞
收藏
分享

微信扫一扫

【华为OJ12】字符串反转


题目描述


写出一个程序,接受一个字符串,然后输出该字符串反转后的字符串。例如:


import java.util.Scanner;

public class Main{
public static String reverseStr(String str){
if(str==null ||str.length()<=0)
return null;
char[] strChar=str.toCharArray();
int len=strChar.length;
int begin=0;
int end=len-1;
while(begin<end){
char temp=strChar[begin];
strChar[begin]=strChar[end];
strChar[end]=temp;
begin++;
end--;
}
return String.valueOf(strChar);
}

public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
String str=sc.nextLine();
System.out.print(reverseStr(str));
}
sc.close();
}
}


举报

相关推荐

0 条评论