Java基础题,求大神看看

2024-12-28 07:04:03
推荐回答(1个)
回答1:

package test0324;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PrintTest {

/**
* @param args
*/
public static void main(String[] args) {
InputStreamReader ir;
BufferedReader in;
ir = new InputStreamReader(System.in);//创建输入流对象
in = new BufferedReader(ir);
System.out.println("请输入字符串:");
try {
String s = in.readLine();
System.out.println("您输入的字符串长度是:"+s.length());
System.out.print("逆序输出为:");
for(int i=s.length();i>0;i--){
System.out.print(s.substring(i-1, i));
}
} catch (IOException e) {
e.printStackTrace();
}
}

}