All pastes #32708 Raw Edit

Someone

public text v1 · immutable
#32708 ·published 2005-12-06 20:38 UTC
rendered paste body
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;
		}
	}
}