代码如下:
package LetCode;
public class reverseString {
/*
* 反转字符串
*/
public void reverseString(char[]Char) {
int left=0;
int right=Char.length-1;
char temp;
while(left<right) {
temp=Char[left];
Char[left++]=Char[right];
Char[right--]=temp;
}
}
public static void main (String[]args) {
char[] Char= {'h','e','l','l','0'};
reverseString rev=new reverseString();
rev.reverseString(Char);
System.out.println(Char);//字符串可以直接输出
}
}