Have you read the Scanner API? It has methods for extracting the next integer or next word from a string.