Dictionary

Dictionary - if (firstword.compareTo(newword) < 0) {...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
public class Dictionary { public static void main(String[] args) { System.out.println("Enter the dictionary:"); String dictionary = IO.readString(); System.out.println("Enter a word to insert:"); String newword = IO.readString(); String answer = ""; S int spaceindex = dictionary.indexOf(" "); while (spaceindex != -1) { String firstword = dictionary.substring(0, spaceindex); S
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (firstword.compareTo(newword) < 0) { answer += firstword + " "; } else if (firstword.compareTo(newword) > 0) { answer = answer + newword + " " + dictionary; break; } else { answer += dictionary; break; } dictionary = dictionary.substring(spaceindex + 1); spaceindex = dictionary.indexOf(" "); } IO.outputStringAnswer(answer + dictionary); I } }...
View Full Document

This note was uploaded on 11/03/2009 for the course CS 01-111 taught by Professor Pradiphari during the Fall '09 term at Rutgers.

Ask a homework question - tutors are online