@@ -0,0 +1,1384 @@
+package com.sunny.grokkingalgorithms.gfg.sap;%0A%0A/**%0A * Created by sundas on 5/7/2017.%0A */%0Apublic class ReverseWordAndCapitalizeFirstLetterInASentence %7B%0A%0A  /*%0A  to reverse each word of a sentence with starting letter to be in CAPS%0AInput: my nAMe is john.%0AOutput: Ym Eman Si Nhoj.%0A   */%0A%0A  /**%0A   *%0A   * @param sentence%0A   * @return%0A   */%0A  public static String reverse(String sentence)%7B%0A    String%5B%5D words = sentence.split(%22 %22);%0A    StringBuilder reversed = new StringBuilder();%0A    for(String word : words)%7B%0A      reversed.append(reverseAndCapitalize(word));%0A      /*%0A      If we want to preserve the spaces we can note down the indexes%0A       */%0A      reversed.append(%22 %22);%0A    %7D%0A    return reversed.toString();%0A  %7D%0A%0A  /**%0A   *%0A   * @param word%0A   * @return%0A   */%0A  public static String reverseAndCapitalize(String word)%7B%0A    int left = 0;%0A    int right = word.length() - 1;%0A    char%5B%5D reversed = new char%5Bword.length()%5D;%0A    while(left %3C right)%7B%0A      char rightChar = word.charAt(right);%0A      if(left == 0 && rightChar %3E 96)%7B%0A        rightChar -= 32;%0A      %7D%0A      reversed%5Bleft%5D = rightChar;%0A      reversed%5Bright%5D = word.charAt(left);%0A      left++;%0A      right--;%0A    %7D%0A    return String.valueOf(reversed);%0A  %7D%0A%0A%0A  /**%0A   *%0A   * @param args%0A   */%0A  public static void main(String%5B%5D args) %7B%0A    String sentence = %22my name is john%22;%0A    System.out.println(reverse(sentence));%0A  %7D%0A%7D%0A

Reverse each word in a sentence and capitalize the first letter.