Friday, 6 February 2015

Code a function that receives a string composed by words separated by spaces and returns a string where words appear in the same order but than the original string, but every word is inverted

Example, for this input string "the boy ran" the output would be "eht yob nar" Tell the complexity of the solution class StringDemo2 { static String myRevers(String s) { StringBuilder sb=new StringBuilder(); for (int i=s.length()-1;i>=0;i-- ) { sb.append(s.charAt(i)); } return sb.toString(); } public static void main(String[] args) { String x="the boy ran"; } }

No comments:

Post a Comment