Java Code Example: for loop to store even and odd items in lists

import java.util.ArrayList;
import java.util.List;

class Cube {
    public static void main(String[] args) {
        int odd = 0, even = 0;

        List<Integer> oddNumbers = new ArrayList<>();
        List<Integer> evenNumbers = new ArrayList<>();

        for (int i = 0; i < 20; i++) {
            if (i % 2 == 0) {
                even += i;
                evenNumbers.add(i);
            } else {
                odd += i;
                oddNumbers.add(i);
            }
        }

        System.out.println("Even Numbers: " + evenNumbers.toString());
        System.out.println("Sum of even numbers: " + even);
        System.out.println("Odd Numbers: " + oddNumbers.toString());
        System.out.println("Sum of odd numbers: " + odd);
    }
}
Output
Even Numbers: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
Sum of even numbers: 90
Odd Numbers: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
Sum of odd numbers: 100