[Java] Easy Prefix Product
```\nclass ProductOfNumbers {\n    private final List list;\n    private int lastProduct = 1;\n\n    public ProductOfNumbers() {\n        this.list = new ArrayL
```\nclass ProductOfNumbers {\n    private final List<Integer> list;\n    private int lastProduct = 1;\n\n    public ProductOfNumbers() {\n        this.list = new ArrayList<>();\n    }\n\n    public void add(int num) {\n        if (num == 0) {\n            list.clear();\n            lastProduct = 1;\n        } else {\n            lastProduct *= num;\n            list.add(lastProduct);\n        }\n    }\n\n    public int getProduct(int k) {\n        final int index = list.size() - k;\n        if (index > 0) return lastProduct / list.get(index - 1);\n        if (index == 0) return lastProduct;\n\n        return 0;\n    }\n}
['Java']