Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Demo {
- public static void main(String[] args) {
- Scanner userIn = new Scanner(System.in);
- ArrayList<String> userStrings = new ArrayList<String>();
- ArrayList<Integer> userIntegers = new ArrayList<Integer>();
- String input;
- while (true) {
- input = userIn.nextLine();
- if (input.equals("quit")) {
- userIn.close();
- break;
- }
- try {
- userIntegers.add(Integer.parseInt(input));
- } catch (NumberFormatException e) {
- userStrings.add(input);
- }
- }
- for (Integer userInt : userIntegers) {
- System.out.print(userInt + " ");
- }
- System.out.println();
- for (String userString : userStrings) {
- System.out.print(userString + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement