1 /** 2 * 倒着输出 3 * @param originStr 4 * @return 5 */ 6 public static String reverse(String originStr) { 7 if(originStr == null || originStr.length() <= 1) 8 return originStr; 9 String substring = originStr.substring(1); 10 char charAt = originStr.charAt(0); 11 return reverse(substring) + charAt; 12 }
1 /** 2 * 3 *demo 4 */ 5 6 public static void main(String[] args) throws Exception{ 7 for (int i = 0; i < 1; i++) { 8 String string = reverse("abc"); 9 System.out.println(string); //cba 10 } 11 }