递归翻转string Reverse a String recursively


public class ReverseString {

		public static String rev(String s) {
			if (s.length() == 0) {
				return "";
			} else {
				return s.charAt(s.length() - 1)
						+ rev(s.substring(0, s.length() - 1));
			}
		}

		public static void main(String args[]) {

			String s = new String("hello");
			System.out.println(rev(s));
		}
	}


你可能感兴趣的:(Interview)