最重要的是str.split(),按字符分割成一个一个小元素

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        
        while(scan.hasNext()){
            String str = scan.nextLine();
            String[] strs = str.split(" ");
            int size = strs.length;
            String t = "a";
            for(int i = 0; i<size/2; i++){
                t = strs[i];
                strs[i] = strs[size - 1-i];
                strs[size-1-i] = t;
            }
            for(String s : strs){
                System.out.print(s+ " ");
            }
        }
        
    }
}