1) Use String.split, then try to parse each element, catching the NumberFormatExceptions for non-numbers.
2) Use java.util.regex.Pattern with the right regular expression.
3) Use java.util.Scanner and its hasNext(), next(), hasNextInt() and nextInt() methods.
Zandis, although your solution was quite good, I would like to ask you to LetThemDoTheirOwnHomework. In other words, don't provide full answers where a hint will help the towards the topic starter to find the answer themselves.