Java || With few lines of code || Using ArrayList || Prefix Product 
CodeStraightForwardPrefix Product

# Code

## *StraightForward*

```java []
class ProductOfNumbers {
    ArrayList<Integer> q;
    public ProductOfNumbers() {
        q=new ArrayList<>();
    }
    
    public void add(int num) {
        q.add(0,num);
    }
    
    public int getProduct(int k) {
        int mul=1;
        for(int i=0;i<k;i++){
            mul*=q.get(i);
        }
        return mul;
    }
}
```
## *Prefix Product*

```java []
class ProductOfNumbers {

    private List<Integer> l;
    public ProductOfNumbers() {
        this.l = new ArrayList<>();
    }
    
    public void add(int num) {
        if (num == 0) {
            l = new ArrayList<>();
            return;
        }
        else if (l.isEmpty()) {
            l.add(num);
        }
        else {
            l.add(l.get(l.size()-1)*num);
        }
    }
    
    public int getProduct(int k) {
        if (k < 1 || k > l.size()) return 0;
        if (k == l.size()) return l.get(l.size()-1);
        return l.get(l.size()-1)/l.get(l.size()-1-k);
    }
}
```
['Java']