import java.util.Scanner;

public class test2{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("请输入要测试的字符串:");
String str = input.nextLine();
test2.test(str);
}
public static void test(String str){

String[] strArr = str.split("\\s+|[,]");

StringBuffer result = new StringBuffer();

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

result.append(strArr[i] + " ");


}

result.setCharAt(str.length()-0, (char) 0);

System.out.println("颠倒顺序后的字符串:: "+result.toString());

}
}

单元测试方法:

import org.junit.After;
import org.junit.Test;

public class test2Test {

@Test
public void test() throws Exception {
String str="how are you";
test2.test(str);
}

}

相关文章:

  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2021-04-22
  • 2022-12-23
  • 2021-06-15
猜你喜欢
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
  • 2021-11-12
  • 2021-05-15
  • 2022-12-23
相关资源
相似解决方案