Пишу Java программу. Для того, чтобы остановить цикл ввода значений в список, нужно ввести null. Клавиша Enter не работает, а слово "null" принимает за строку и выводит исключение. Как ввести null?
Вот код цикла:
ArrayList<Integer> coll = new ArrayList<>();
int full = 0;
while(true) {
System.out.print("Enter " + (coll.size() + 1) + "number in
collection (press enter to exit): ");
Integer element = (Integer)new Scanner(System.in).nextInt();
if (element != null) {
coll.add(element);
full += element;
} else {
for (int el = 0; el < coll.size(); el++) {
System.out.println((el + 1) + " element in collection: " +
coll.get(el));
}
System.out.println();
System.out.println("Collection addition result: " + full);
break;
}