请指导一下关于反转时toCharArray()方法的使用!附:程序
[code]import java.io.*;
public class D {
public static void main(String[] args){
BufferedReader write = new BufferedReader(new InputStreamReader(System.in)); //(获取输入的字符串)
String input = write.toString();//
char[] shuzu = input.toCharArray(); //将刚才输入的字符串转成数组,这步,我不是很确定!
if(input.length() <=1 && input.length()> =0){
System.out.println( "it 's wrong! ");
}else{
for(int i = shuzu.length; i <=shuzu.length ; i--){
System.out.print(shuzu[i] + " ");
}
}
}
}
[/code]
------解决方案--------------------for(int i = shuzu.length; i <=shuzu.length ; i--){
这个上来就报错
应该是:
for(int i = shuzu.length - 1; i > = 0; i--){
------解决方案--------------------String input = write.toString();//
改成
String input =write.readline();