Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- public class Hello_Java{
- public static void main(String[] args){
- Scanner input = new Scanner(System.in);
- String s = input.nextLine();
- ArrayList<Integer> numbers = new ArrayList<Integer>();
- List<String> letters = new ArrayList<String>(Arrays.asList(s.split(" ")));
- for (int i = 0; i < letters.size(); i++) {
- if (getValue(letters.get(i))) {
- numbers.add(Integer.parseInt(letters.get(i)));
- }
- else {
- continue;
- }
- }
- System.out.println(Arrays.asList(numbers));
- }
- public static boolean getValue(ArrayList<String> letters.get(i) ){
- try
- {
- Integer.parseInt(letters.get(i));
- return true;
- } catch(NumberFormatException nfe)
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement