题解 | #倒置字符串#
倒置字符串
https://www.nowcoder.com/practice/ee5de2e7c45a46a090c1ced2fdc62355
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); String[] strArr = str.split(" "); int left = 0, ritht = strArr.length-1; while(left < ritht){ String swap = strArr[left]; strArr[left] = strArr[ritht]; strArr[ritht] = swap; left++; ritht--; } StringBuilder sb = new StringBuilder(); for(int i =0;i<strArr.length;i++){ sb.append(strArr[i]); if(i != strArr.length -1){ sb.append(' '); } } System.out.println(new String(sb)); } }