Functions perfectly when I run it and when I enter a text it catches and displays the previous numbers entered and added into the ArrayList.
I appreciate the assistance guys!
package com.codegym.task.task09.task0921;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/* 1. The program must read data from the keyboard.
2. Don't change the main method.
3. The main method should not throw exceptions.
4. The readData method must contain a try-catch block.
5. If the user enters text rather than a number, the program should display all previously entered numbers.
*/
public class Solution {
public static void main(String[] args) {
readData();
}
public static void readData() {
//write your code here
ArrayList<Integer> intList = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
while (true) {
int s = Integer.parseInt(reader.readLine());
intList.add(s);
}
}
catch (Exception x) {
System.out.println(intList);
}
}
}