首先在这里简单说明一下Java的输入操作:
Scanner sc=new Scanner(System.in);
String s1=sc.next();//不能读入空格,遇到空格则会结束输入
String s2=sc.nextLine();//可以读入空格,以enter作为结束符
package B1009;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int len=s.length();
int f=len-1;
while(f>=0)
{
while(s.charAt(f)!=' '&&f>0)
f--;
if(f>0)
{
System.out.print(s.substring(f+1,len));
System.out.print(" ");
}
else
System.out.print(s.substring(0,len));
len=f--;
}
}
}