从键盘输入一个字符串,按反序输出用JAVA怎么实现
发布网友
发布时间:2023-09-09 08:51
我来回答
共1个回答
热心网友
时间:2024-12-05 12:19
public static void main(String[] args) throws IOException {
while (true) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your value:");
String str = br.readLine();
if (null == str || str.trim().length() == 0) {
System.out.println("请输入合格字符串!");
} else {
System.out.println("输入的字符串是:" + str);
char[] s = str.toCharArray();
String out = "";
for (int i = s.length - 1; i >= 0; i--) {
out += String.valueOf(s[i]);
}
System.out.println("字符串倒序是:" + out);
}
}
}