/* The user will be prompted to enter a four word phrase from the keyboard, to be read as a single string, i.e. How now brown cow The user will use the appropriate String methods, to build another String with the words in reverse order, to be displayed i.e. cow brown now How Used to demonstrate String methods author: course: 15-100 Intro to Java Programming section: date: */ import java.io.*; import javax.swing.JOptionPane; public class ReverseString { public static void main(String args[]) { String sentence; sentence = JOptionPane.showInputDialog("Please enter a four word sentence"); int k = sentence.indexOf(" "); String word1 = sentence.substring(0,k); //System.out.println(word1); sentence = sentence.substring(k+1); k = sentence.indexOf(" "); String word2 = sentence.substring(0,k); sentence = sentence.substring(k+1); k = sentence.indexOf(" "); String word3 = sentence.substring(0,k); String word4 = sentence.substring(k+1); System.out.println(word4 + " " + word3 + " " + word2 + " " + word1); } }