把一个英语句子中的单词次序颠倒后输出。例如输入“how are you”,输出“you are how”;

时间:2022-09-10 11:47:50

import java.util.Scanner;

public class Test2 {

public void reverse(String str) {

String[] wordArray = str.split(" ");

System.out.print("颠倒输出:");

for (int i = wordArray.length - 1; i >= 0; i--) {

System.out.print(wordArray[i] + " ");

}

}

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("请输入一句英语句子:");

String str = input.nextLine();

Test test = new Test();

test.reverse(str);

}

}