Task : An array consists of natural numbers.
The number of elements is unknown, but if the i-th element of the array is == 0, then the reading of elements from the keyboard is stopped and the maximum element of the array is output.
Preface : Did not work before with the dynamic array ListArray
My code is :
int rez = 1; int max=0; ArrayList<Integer> b = new ArrayList<>(); b.ensureCapacity(100); System.out.println("Введите элементы"); while(!(rez==0)){ int j; for (j = 0; j<b.size(); j++) { b.set(j, in.nextInt()); if(!(b.get(j)==0)){ if(b.get(j)>max){b.set(j, b.get(j));} }else{ rez=0; break; } } } System.out.println("Максимальный элемент вашего массива = " + max);