将输入字符串中的非字母用"-"替换,然后以"-"分割,再逆序输出
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
char[] c = new char[str.length()];
for(int i = 0; i<str.length(); i++){
if(((int)(str.charAt(i))>=65 && (int)(str.charAt(i))<=90) || ((int)(str.charAt(i))>=97 && (int)(str.charAt(i))<=122)){
c[i] = str.charAt(i);
}else{
c[i] = '-';
}
}
str = str.copyValueOf(c);
String[] subStr = str.split("-");
for(int i = subStr.length-1; i>=0; i--){
if(subStr[i] != ""){
System.out.print(subStr[i]+" ");
}
}
}
}