Java解 | #HJ31单词倒排#倒置字符串# I like beijing # beijing like I #
Posted 闭关苦炼内功
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java解 | #HJ31单词倒排#倒置字符串# I like beijing # beijing like I #相关的知识,希望对你有一定的参考价值。
单词倒排#倒置字符串# I like beijing # beijing like I
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
StringBuffer sb = new StringBuffer(in.nextLine());
for(int i = 0;i < sb.length(); i++){
char c = sb.charAt(i);
// I like beijing beijing like I
if(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'){
// I like beijing. beijing. like I
// if(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c == '.'){
continue;
}
sb.replace(i,i+1," ");
}
String[] sts = sb.toString().split(" ");
for(int i=sts.length-1;i>0;i--){
if(sts[i].equals(" ")){
continue;
}
System.out.print(sts[i] + " ");
}
System.out.println(sts[0]);
}
}
}
以上是关于Java解 | #HJ31单词倒排#倒置字符串# I like beijing # beijing like I #的主要内容,如果未能解决你的问题,请参考以下文章