从键盘输入一个字符串,按反序输出用JAVA怎么实现
1个回答
展开全部
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);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询