import java.util.Scanner;
public class test {
public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
// System.out.println("请输入你的年龄:");
// int age = sc.nextInt();
// System.out.println("请输入你的姓名:");
// String name = sc.nextLine();//nextline 只有接到回车
// System.out.println("请输入你的工资:");
// float salary = sc.nextFloat();
// System.out.println("你的信息如下:");
// System.out.println("姓名:"+name+"\n"+"年龄:"+age+"\n"+"工资:"+salary);
Scanner sc = new Scanner(System.in);
String str=sc.nextLine();
char[] chars=str.toCharArray();
String s="";
for(int i=str.length()-1;i>=0;i--){
if(chars[i]==' '){
StringBuffer buffer = new StringBuffer(s);
System.out.print(buffer.reverse()+" ");//反转输出单词
s="";
}
else {
s=s+chars[i];
}
}
for(int i=0;i<str.length();i++){
if(chars[i]!=' '){
System.out.print(chars[i]);
}
else
break;
}
}
}
句子反转
最新推荐文章于 2023-08-06 22:09:52 发布