Reverse a string in a sentence

在整句话中,使整个句子反转

	public static String sentenceReverse(String src) {

		char[] contents = src.toCharArray();
		final int length = contents.length;
		if (length < 2)
			return src;
		char[] res = new char[length];
		for (int srcCursor = length - 1; srcCursor >= 0; srcCursor--) {
			res[length - srcCursor - 1] = contents[srcCursor];
		}
		return String.valueOf(res);


测试
public static void main(String[] args) {
		String sb = "I love you very much.";

		String bs=sentenceReverse(sb);
		System.out.print(bs);
	}


输出结果:.hcum yrev uoy evol I
达到要求。


现在要求输出的结果为      .much very you love I



你可能感兴趣的:(String)