java学习笔记:字符串的反转的代码
public class Main { public static String reverse(String originStr) { if(originStr == null || originStr.length() <= 1) return originStr; return reverse(originStr.substring(1)) + originStr.charAt(0); } public static void main(String[] args) { // System.out.println("Hello World!"); // 测试代码 String str1 = "Hello"; String str2 = reverse(str1); System.out.println(str1); // Hello System.out.println(str2); // olleH } }