A user has to input only numbers(int, float, double) into an ArrayList. If a user inputs anything but numbers, an exception InputMismatchException must be thrown.
I thought of using Number class.
Scanner input = new Scanner(System.in);
ArrayList<Number> number = new ArrayList<Number>();
System.out.println("Enter number");
(data_type???) number_var = input.??????;
number.add(number_var);
This code will be in do while asking user if he/she wants to continue to give input or not. The only problem is how to restrict user to give input as only numbers. This should be done without creating another class but a method is allowed to restrict user.