class SplitWords { public static void main (String [] args) { System.out.println("Enter message to be translated: "); String message = Console.readString(); int indexOfSpace = 0; int wordCount = 0; //counts the number of spaces in the message, giving the number of words in the message while(indexOfSpace != -1) { indexOfSpace = message.indexOf(indexOfSpace, ' '); wordCount++; } indexOfSpace = 0; String [] arrayName = new String[wordCount+1]; int currentSpace = 0; int i = 0; while (indexOfSpace != -1) { currentSpace = message.indexOf(indexOfSpace, ' '); //this saves the index of the newly found space if(currentSpace != -1) { arrayName[i] = message.substring(indexOfSpace, currentSpace); i++; } else { arrayName[i] = message.substring(indexOfSpace); i++; } indexOfSpace = currentSpace; } } }