import java.util.Stack;
public class Reverse {
public static void reverse(String str){
Stack<String> st=new Stack<String>();
StringBuffer sb;
int i=0;
while(i<str.length()){
if(str.charAt(i)==' '||i==str.length()-1){
int j=0;
if(str.charAt(i)==' '){j=i-1;}
if(i==str.length()-1){j=i;}
while(str.charAt(j)!=' '&&j!=0)
{
j--;
}
sb=new StringBuffer();
for(;j<i;j++){
sb.append(str.charAt(j));
}
st.push(sb.toString());
}
i++;
}
System.out.println(st.pop());
System.out.println(st.pop());
System.out.println(st.pop());
System.out.println(st.pop());
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="I am a student.";
reverse(str);
}
}