Advertisement
Guest User

Untitled

a guest
Jan 16th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1.  
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7.  
  8. public class Hello_Java{
  9. public static void main(String[] args){
  10. Scanner input = new Scanner(System.in);
  11. String s = input.nextLine();
  12. ArrayList<Integer> numbers = new ArrayList<Integer>();
  13. List<String> letters = new ArrayList<String>(Arrays.asList(s.split(" ")));
  14. for (int i = 0; i < letters.size(); i++) {
  15. if (getValue(letters.get(i))) {
  16. numbers.add(Integer.parseInt(letters.get(i)));
  17. }
  18. else {
  19. continue;
  20. }
  21. }
  22. System.out.println(Arrays.asList(numbers));
  23. }
  24. public static boolean getValue(ArrayList<String> letters.get(i) ){
  25. try
  26. {
  27. Integer.parseInt(letters.get(i));
  28. return true;
  29. } catch(NumberFormatException nfe)
  30. {
  31. return false;
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement