If this error appears because of comparing index 0 and index 1 -> print max of those 2, increment and comparing next pair and so on? Any suggestions folks? Appreciate all feedback.
package pl.codegym.task.task05.task0532;

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

/*
Zadanie z algorytmami
*/

public class Solution {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        ArrayList<Integer> list = new ArrayList<Integer>();

        int size = scanner.nextInt();

        for (int i = 0; i < size; i++) {
            int number = scanner.nextInt();
            list.add(number);

            int maksimum = list.get(i);


            if (maksimum == list.get(i)) {
                maksimum = number;
            } else {
                maksimum = list.get(0);
            }
            System.out.println(maksimum);
        }
    }


}