Note the parameter wordssofar always starts and ends

This preview shows page 15 - 21 out of 25 pages.

Note: The parameter, wordsSoFar , always starts and ends with a blank space. For example, the following code: String words = " dog catfish hen pig "; words = addWordIfNotAlreadyInString(words, "bird"); System.out.println("1. " + words); words = addWordIfNotAlreadyInString(words, "cat"); System.out.println("2. " + words); words = addWordIfNotAlreadyInString(words, "bee"); System.out.println("3. " + words); words = addWordIfNotAlreadyInString(words, "pig"); System.out.println("4. " + words); would print: 1. dog catfish hen pig bird 2. dog catfish hen pig bird cat 3. dog catfish hen pig bird cat bee 4. dog catfish hen pig bird cat bee private String addWordIfNotAlreadyInString(String wordsSoFar, String word){ } (7 marks)
Image of page 15

Subscribe to view the full document.