Write a function (in your preferred language C, C++, or Java) that will take the given string and return the reverse. (ie. input:"abc def ghi" output:"ihg fed cba") Optimize the above code (if possible). Now knowing that the original function you wrote in pt1 is being used by other programs and cannot be modified write another function that when called will utilize the function from pt1 to only reverse the words in the sentence. (ie. input:"abc def ghi" output:"ghi def abc") Test your code.
Anónimo
public class TestRun2 { public static void main(String[] args) { String inputString = "abc def ghi"; System.out.println(reverseString(inputString)); // now reverse the words System.out.println(reverseWords(inputString)); } public static String reverseString(String input) { char[] inputCharArray = input.toCharArray(); char[] returnCharArray = new char[inputCharArray.length]; for(int i=0; i