package dk.itu.oop.lecture5; public class CarterStory{ public static final String WORDS = "President Jimmy Carter was attacked by a rabbit during a " + "fishing trip in Plains, Georgia. The rabbit, which may have " + "been fleeing a predator, swam toward his boat, \"hissing " + "menacingly, its teeth flashing and nostrils flared.\" President " + "Carter was forced to swat at the vicious beast with a canoe " + "paddle, which apparently scared it off." + "Upon his return to the White House, Carter told his staff " + "about the furry amphibian's assault. Most of them refused "+ "to believe him, insisting that rabbits can't swim (although " + "since most mammals can swim, there's no reason to believe " + "that rabbits cannot), and that even if they could, they " + "certainly wouldn't attack humans, and certainly not presidents. " + "Fortunately, a White House photographer had been on the " + "scene, and had recorded the bizarre attack. The " + "photograph showed Carter with his paddle raised, warding off " + "a small creature which might, or might not, have been a rabbit. " + "One staffer was quoted as saying, \"You couldn't tell " + "what it was.\" Undaunted by their skepticism, Carter had " + "the image enlarged, and there it was--a killer bunny rabbit, " + "apparently bent on assassinating the president."; public static void printWords(String s){ int index = 0; while (index < s.length() ){ // all words uptil, but not including index has been printed while (index < s.length() && Character.isLetter( s.charAt(index) ) ){ // all letters in this word uptil, but not including index // has been printed System.out.print( s.charAt(index) ); index++; } System.out.println(); while (index < s.length() && !Character.isLetter( s.charAt(index) ) ){ // all non letters since last word, uptil but not including index // has been skipped index++; } } } public static void main(String[] args){ printWords(" her er en!. stor åg en større æble grød"); } }