package demo.fanzhuan;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class Revert {
public String reserv(String list){
return new StringBuffer(list).reverse().toString();
// return new StringBuilder(list).reverse().toString();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入字符,空格隔开:");
Scanner sc= new Scanner(System.in);
String str=sc.nextLine();
Revert rt = new Revert();
String a=rt.reserv(str);
String[] sArr=a.split(" ");
List<String> list= new ArrayList<String>();
list=Arrays.asList(sArr);
System.out.println("------------倒叙输出---------------");
System.out.println(list);
}
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class Revert {
public String reserv(String list){
return new StringBuffer(list).reverse().toString();
// return new StringBuilder(list).reverse().toString();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入字符,空格隔开:");
Scanner sc= new Scanner(System.in);
String str=sc.nextLine();
Revert rt = new Revert();
String a=rt.reserv(str);
String[] sArr=a.split(" ");
List<String> list= new ArrayList<String>();
list=Arrays.asList(sArr);
System.out.println("------------倒叙输出---------------");
System.out.println(list);
}
}
-------------------输入输出-----------
请输入字符,空格隔开:
1 2 3 4 5
------------倒叙输出---------------
[5, 4, 3, 2, 1]