SHARE
TWEET

Untitled

a guest Jun 19th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class WordsReverse {
  2.  
  3.     public static void main(String[] args) {
  4.         String test = "big brown fox jumped over   a lazy dog";
  5.         StringBuilder result = new StringBuilder();
  6.         int start = 0;
  7.         for(int end = 0; end < test.length(); end++) {
  8.             if(test.charAt(end) == ' ') {
  9.                 for(int i = end-1; i >= start; i--) {
  10.                     result.append(test.charAt(i));
  11.                 }
  12.                 result.append(" ");
  13.                 start = end+1;
  14.             }
  15.         }
  16.  
  17.         System.out.println(result.toString());
  18.  
  19.     }
  20. }
RAW Paste Data
Want to get better at Java?
Learn to code Java in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top