Scanner sc = new Scanner(System.in);
System.out.print("Enter the number to reverse ");
String mystring = sc.nextLine();
char[] my_3 = mystring.toCharArray(); // string converted into array
如何将char数组转换回字符串
for (int i = my_3.length - 1; i >= 0; i--) {
System.out.print(my_3[i]);
String b = new String(my_3[i]);
}
答案 0 :(得分:1)
试试这个。
String mystring = "abcde";
String reverse = new StringBuilder(mystring).reverse().toString();
System.out.println(reverse); // -> edcba