
public class Main2 {

	public static void print(int n){
		if(n==0)
			return;
		else
		{
			System.out.println(n);
			print(n-1);
		}
	}

	public static void anagrams(String pref,String word){
		if(word.length()<=1){
			System.out.println(pref+word);
		}
		else
			for(int i=0;i<word.length();++i){
				char c=word.charAt(i);
				String prefex=word.substring(0, i);
				String suffex=word.substring(i+1);
				anagrams(pref+c, prefex+suffex);
			}

	}

	public static void reverse(String s){

		int index =s.lastIndexOf(" ");

		if(index<0)
			System.out.println(s);
		else{
			String pref=s.substring(0, index);
			
			String suff = s.substring(index+1);
			
			System.out.println(suff);
			reverse(pref);
		}
	}
	/*public static void reverse(String s){
		int index = s.lastIndexOf(" ");
		if(index<0)
			System.out.println(s);
		else{
			String pref = s.substring(0, index);
			String suff = s.substring(index+1);
			System.out.println(suff);
			
			reverse(pref);
		}
	}*/

	public static void main(String[] args) {
		reverse("welcome to Ahmad");
		
	}

}
