编写一个应用程序,接收用户输入端一行字符串,统计字符个数,然后反序输出。
执行代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class chengxu2 {
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.println("反序输出为:");
for (int i = s.length(); i > 0; i--) {
System.out.print(s.charAt(i - 1));
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}
执行结果:
· 先调试再运行