Advertisement
zidandazizo

boso walikan

Feb 24th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. String str = "hello brave new world";
  2. tStr.reverseWordByWord(str)
  3.  
  4. public String reverseWordByWord(String str){
  5.         int strLeng = str.length()-1;
  6.         String reverse = "", temp = "";
  7.  
  8.         for(int i = 0; i <= strLeng; i++){
  9.             temp += str.charAt(i);
  10.             if((str.charAt(i) == ' ') || (i == strLeng)){
  11.                 for(int j = temp.length()-1; j >= 0; j--){
  12.                     reverse += temp.charAt(j);
  13.                     if((j == 0) && (i != strLeng))
  14.                         reverse += " ";
  15.                 }
  16.                 temp = "";
  17.             }
  18.         }
  19.  
  20.         return reverse;
  21.     }
  22.  
  23. the phrase at the moment becomes:
  24.  
  25.     olleh evarb wen dlrow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement