private static void reverseWords(String input)
    {
        StringBuilder output = new StringBuilder();
        char[] inputStrArray = input.toCharArray();
        
        //first reverse the complete char array
        reverseCharArray(inputStrArray,0,inputStrArray.length);
        //now iterate over it for each word and then reverse it
        int count =0;
        int lastspace=0;
        for(char c : inputStrArray)
        {
            if(c==' ')
            {
                reverseCharArray(inputStrArray, lastspace, count);
                //next word's beginning
                lastspace = count+1;
            }
            count++;
        }
        //for the last word
        reverseCharArray(inputStrArray, lastspace, inputStrArray.length);
        System.out.println(inputStrArray);
    }