Hi,
My code works fine while running. Unfortunately it fails the third condition. I know it is because of "throws IOException". However, when I had left that out, my code did not compile due to an unhandled IOException.
Best regards
package com.codegym.task.task09.task0921;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Method in a try-catch
*/
public class Solution {
public static void main(String[] args) throws IOException{
readData();
}
public static void readData() throws IOException
{List<Integer> numbers = new ArrayList();
try {
while (true) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s1 = reader.readLine();
int a = Integer.parseInt(s1);
numbers.add(a);
}
}
catch (NumberFormatException e)
{
for (Integer num: numbers) {
System.out.println(num);
}
}
}
}