// Collection of code snippets by Arne VajhÃ¸j 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.*;

public class Token {
   public static void main(String[] args) {
      String a = "Jeg gik mig over sø og land der mødte jeg en gammel mand";
      StringTokenizer p = new StringTokenizer(a, " ");
      String temp = p.nextToken();
      while (p.hasMoreTokens()) {
         String word = p.nextToken();
         if(temp.length() + 1 + word.length() > 10) {
            System.out.println(temp);
            temp = word;
         } else {
            temp = temp + " " + word;
         }
      }
      if(temp.length() > 0) {
         System.out.println(temp);
      }
   }
}
