// SplittingSentence.java Copyright (c) 2006 Kari Laitinen // http://www.naturalprogramming.com // 2006-02-15 File created. // 2006-02-15 Last modification. // A solutions to Exercise 8-9. import java.util.* ; class SplittingSentence { public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; System.out.print( "\n Please, type in a sentence. \n\n " ) ; String given_sentence = keyboard.nextLine() ; System.out.print( "\n Splitted sentence with reversed words: \n " ) ; // See program SplittingAtoms.java for more information related // to the use of the split() method. String[] words_of_the_sentence = given_sentence.split( "[ ]" ) ; for ( int word_index = 0 ; word_index < words_of_the_sentence.length ; word_index ++ ) { System.out.print( "\n " ) ; String word_to_print = words_of_the_sentence[ word_index ] ; int character_index = word_to_print.length() ; while( character_index > 0 ) { character_index -- ; System.out.print( word_to_print.charAt( character_index ) ) ; } } } }