java编写一个应用程序,接收用户输入的一行字符串,统计字符个数,然后反序输出

2024-11-08 21:36:11
推荐回答(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();
}
}

}